• Remix
  • Share
  • New Entry

  • Vibha

  • /
  • Diwali Diya Flame Animation

on 31 Oct 2024
  • 20
  • 66
  • 0
  • 0
  • 1447
function drawframe(f)
% Create a new figure with a black background
figure('Color', 'k', 'Position', [100, 100, 800, 600]);
axis equal;
axis off;
% Parameters for the flame
flame_base = 0.2;
glow_radius = 0.15;
flicker_amplitude = 0.2 * (rand() - 0.5);
flame_height = 0.5 + flicker_amplitude;
% Define the flame shape (upright triangle)
x_flame = [-flame_base / 2, 0, flame_base / 2];
y_flame = [0, flame_height, 0];
% Create a gradient for the flame (from bright yellow to orange)
num_colors = 50;
flame_colors = [1, 1, 0; 1, 0.5, 0];
gradient_colors = zeros(num_colors, 3);
% Generate the gradient colors
for j = 1:3
gradient_colors(:, j) = linspace(flame_colors(1, j), flame_colors(2, j), num_colors);
end
% Create the diya base (crescent shape)
theta = linspace(0, pi, 100);
r_outer = 0.5;
r_inner = 0.35;
% Coordinates for the inverted crescent shape
x_base_outer = r_outer * cos(theta);
y_base_outer = -r_outer * sin(theta);
x_base_inner = r_inner * cos(theta);
y_base_inner = -r_inner * sin(theta);
% Draw diya base (only once)
hold on;
fill(x_base_outer, y_base_outer, [0.8 0.4 0.2], 'EdgeColor', 'none');
fill([-r_outer, x_base_inner, r_outer], [0, y_base_inner, 0], [0.8 0.4 0.2], 'EdgeColor', 'none');
% Draw the flame with color gradient
for j = 1:num_colors - 1
fill(x_flame, y_flame + glow_radius * (num_colors - j) / num_colors, ...
gradient_colors(j, :), 'EdgeColor', 'none');
end
% Create the glowing effect around the flame
for j = 1:num_colors - 1
fill(x_flame, ...
y_flame + glow_radius + (glow_radius * (num_colors - j) / num_colors), ...
[1, 1, 0], 'EdgeColor', 'none', 'FaceAlpha', 0.15 * (num_colors - j) / num_colors);
end
hold off;
% Set fixed axes limits to prevent lateral disturbances
xlim([-0.7, 0.7]);
ylim([-1, 0.7]);
set(gca, 'Color', 'k');
% Capture the frame
drawnow;
end
function createMovie()
% Set up video writer
v = VideoWriter('diwali_diya_animation.mp4', 'MPEG-4');
v.FrameRate = 24; % Frame rate
open(v);
% Create a movie by generating frames
for loop = 1:3
for f = 1:96
% Call the drawframe function to create the current frame
drawframe(f);
frame = getframe(gcf); % Capture the current frame
writeVideo(v, frame);
cla; % Clear axes for the next frame
end
end
% Close the video file
close(v);
disp('Movie created successfully!');
end
Movie
Audio

This submission does not have audio.

Remix Tree