• Remix
  • Share
  • New Entry

  • Sid

  • /
  • Solar system

on 18 Nov 2023
  • 10
  • 28
  • 0
  • 0
  • 1712
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Solar System Animation with 8 Planets (Larger Sizes) - drawframe function
% Solar System Animation with 8 Planets (Larger Sizes)
figure;
axis off; % Remove axes
hold on;
% Sun parameters
sun_radius = 0.2 * 1.5;
sun_color = [1, 0.8, 0]; % Yellow
% Planets parameters
planet_names = {'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'};
num_planets = length(planet_names);
planet_colors = rand(num_planets, 3); % Random colors for each planet
planet_sizes = [0.0553, 0.136, 0.142, 0.075, 1, 0.834, 0.365, 0.347] * 1.5; % Larger sizes
planet_speeds = linspace(0.02, 0.2, num_planets); % Varying rotation speeds
% Calculate planet distances to avoid overlap
planet_distances = zeros(1, num_planets);
planet_distances(1) = 0.4 * 1.5; % Starting distance from the sun
for i = 2:num_planets
% Ensure no overlap by adjusting distance based on the sum of radii
planet_distances(i) = planet_distances(i-1) + planet_sizes(i-1) + planet_sizes(i) + 0.05 * 1.5;
end
% Draw Sun at the center
draw_circle(0, 0, sun_radius, sun_color);
% Draw white orbits
for i = 1:num_planets
draw_orbit(planet_distances(i), [1, 1, 1]);
end
% Draw planets
for i = 1:num_planets
angle = planet_speeds(i) * f;
x = planet_distances(i) * cos(angle);
y = planet_distances(i) * sin(angle);
draw_circle(x, y, planet_sizes(i), planet_colors(i, :));
% Display planet names
text(x, y, planet_names{i}, 'Color', [1, 1, 1], 'HorizontalAlignment', 'center', 'FontSize', 8 * 1.5);
end
% Add text on the right bottom corner
text(max(planet_distances) + 0.5, -max(planet_distances) - 1, 'Made by Sid Gupta', 'Color', [1, 1, 1], 'FontSize', 10, 'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom');
% Remove axis markings and labels
set(gca, 'XTick', []);
set(gca, 'YTick', []);
set(gca, 'XColor', 'none');
set(gca, 'YColor', 'none');
% Set axis properties to fit all planets within the screen
axis([-max(planet_distances)-1, max(planet_distances)+1, -max(planet_distances)-1, max(planet_distances)+1]);
axis square;
% Update figure window without pausing
% Set axes color to black
set(gca,'Color','k');
% Set background color to black
set(gcf, 'Color', [0, 0, 0]);
% Update figure window without pausing
drawnow;
end
function draw_circle(x, y, radius, color)
theta = linspace(0, 2*pi, 100);
x_circle = x + radius * cos(theta);
y_circle = y + radius * sin(theta);
fill(x_circle, y_circle, color);
end
function draw_orbit(radius, color)
theta = linspace(0, 2*pi, 100);
x_orbit = radius * cos(theta);
y_orbit = radius * sin(theta);
plot(x_orbit, y_orbit, 'Color', color);
end
Animation
Remix Tree