• Remix
  • Share
  • New Entry

on 8 Nov 2023
  • 5
  • 38
  • 0
  • 1
  • 1505
drawframe(1);
Write your drawframe function below
function drawframe(frame)
clf;
set(gcf, 'Color', 'k'); % Set figure background to black
axis([-1.5 1.5 -1.5 1.5 -1.5 1.5]);
daspect([1 1 1]);
axis off;
hold on;
% Starfield background with varied brightness
num_stars = 1000;
star_pos = 3 * (rand(num_stars, 3) - 0.5);
star_size = rand(1, num_stars) * 3;
star_brightness = rand(1, num_stars);
scatter3(star_pos(:,1), star_pos(:,2), star_pos(:,3), star_size, star_brightness, 'filled');
% Plot stars
star1_pos = [sin(frame*pi/48), cos(frame*pi/48), 0] * 0.3;
star2_pos = [-sin(frame*pi/48), -cos(frame*pi/48), 0] * 0.3;
scatter3(star1_pos(1), star1_pos(2), star1_pos(3), 400, 'y', 'filled');
scatter3(star2_pos(1), star2_pos(2), star2_pos(3), 300, 'r', 'filled');
% Generate planets with orbits
num_planets = 4;
planet_orbits = linspace(0.2, 0.5, num_planets);
for p = 1:num_planets
angle = frame * 2 * pi / 48 + p * (2 * pi / num_planets);
planet_pos = star1_pos + [cos(angle), sin(angle), 0] * planet_orbits(p);
scatter3(planet_pos(1), planet_pos(2), planet_pos(3), 40, 'r', 'filled');
% Orbit trails with varying colors
t = linspace(0, 2*pi, 100);
orbit_x = cos(t) * planet_orbits(p) + star1_pos(1);
orbit_y = sin(t) * planet_orbits(p) + star1_pos(2);
orbit_color = [0.5 + p*(0.1), 0.5 - p*(0.1), 1 - p*(0.1)];
plot3(orbit_x, orbit_y, zeros(size(t)), 'Color', orbit_color, 'LineWidth', 1.5);
end
% Comet
comet_pos = [1.2, -1.5 + mod(frame * 0.1, 3), 0];
comet_tail_len = 15;
comet_tail = comet_pos - [linspace(-0.1, 0, comet_tail_len)', linspace(-0.2, 0, comet_tail_len)', zeros(comet_tail_len, 1)];
plot3(comet_tail(:,1), comet_tail(:,2), comet_tail(:,3), 'w', 'LineWidth', 1.5);
view(0, 90); % Top-down view to better see the orbits
lighting gouraud;
camlight('headlight');
% Title
title('Dance of the Celestials', 'Color', 'w', 'FontSize', 14);
hold off;
drawnow;
end
Animation
Remix Tree