# pip install ivisual
from ivisual import *
AU = 1.496e8 # km
AU = 1e-2 * AU # so that we can see
earth_radius = 6371 # km
def orbit(bodies, radii, years, earth_years=10, _rate=24):
for t in np.linspace(0, earth_years, earth_years * 365):
rate(_rate)
for body, radius, year in zip(bodies, radii, years):
x = radius * np.cos(2*np.pi * t / year)
y = radius * np.sin(2*np.pi * t / year)
body.pos = (x, y, 0)
canvas(width=900, height=600)
sun = sphere(radius = 109 * earth_radius, color = color.red)
earth = sphere(radius = earth_radius, color = color.blue, pos = (AU, 0, 0), make_trail=True)
jupyter = sphere(radius = 10.5 * earth_radius, color = color.orange, pos = (5.2 * AU, 0, 0), make_trail=True)
saturn = sphere(radius = 9.14 * earth_radius, color = color.cyan, pos = (9 * AU, 0, 0), make_trail=True)
orbit(bodies=[earth, jupyter, saturn], radii=[AU, 5.2 * AU, 9 * AU], years=[1, 11.86, 29.5], earth_years=30, _rate=48)