• Remix
  • Share
  • New Entry

on 29 Nov 2023
  • 9
  • 2
  • 0
  • 0
  • 827
drawframe(1);
Write your drawframe function below
function drawframe(frame)
figure(1);
clf;
axis off;
hold on;
switch frame
case num2cell(1:4) % Stable star
plot_star(50, 50, 10, [1 1 0]); % Yellow star
case num2cell(5:10) % Beginning of explosion
expand_factor = 1 + (frame - 10) / 10;
plot_star(50, 50, 10 * expand_factor, [1 0.5 0]); % Orange star
case num2cell(11:35) % Explosion expansion
expand_factor = 2 + (frame - 20) / 5;
plot_star(50, 50, 10 * expand_factor, [1 0 0]); % Red star
case num2cell(36:48) % Explosion dissipation
scatter_particles(frame - 35, 50, 50);
otherwise
disp('Invalid frame number');
end
hold off;
drawnow;
end
function plot_star(x, y, size, color)
% Create star-shaped polygons
num_points = 5; % Number of points in the star
angle = linspace(0, 2*pi, num_points*2 + 1);
x_points = x + size * cos(angle);
y_points = y + size * sin(angle);
% Plot the star
plot(x_points, y_points, 'LineWidth', 3, 'Color', color);
end
function scatter_particles(step, x, y)
% Scatter particles to simulate explosion remnants
num_particles = 100;
angle = rand(1, num_particles) * 2 * pi;
radius = step * rand(1, num_particles) * 5;
scatter(x + radius .* cos(angle), y + radius .* sin(angle), 'r');
end
Animation
Remix Tree