Solar system¶
This example uses the rotate() animation to animate Circle plot objects, and follows a planet with axis_track().
We first create our timeline with our styling:
import diplotocus as dpl
import numpy as np
tl = dpl.Timeline(xlim=(-40,40),ylim=(-40,40),figsize=(5,5),noaxis=True,fig_color='k',bbox_inches='tight')
Then, we create the Sun and define the planets’ properties:
sun = dpl.Circle(xy=(0,0),radius=1,fc='yellow')
sun.plot(360)
planet_infos = [
{'name':'Mercury','d':0.320,'r':0.2440,'col':'#bfbdbc'},
{'name':'Venus' ,'d':0.720,'r':0.6052,'col':'#d4b496'},
{'name':'Earth' ,'d':1.000,'r':0.6371,'col':'#6a87a5'},
{'name':'Mars' ,'d':1.400,'r':0.3390,'col':'#e38266'},
{'name':'Jupiter','d':5.260,'r':6.9911,'col':'#bdb19e'},
{'name':'Saturn' ,'d':9.480,'r':5.8232,'col':'#d4b880'},
{'name':'Uranus' ,'d':19.47,'r':2.5362,'col':'#9dbabd'},
{'name':'Neptune','d':29.88,'r':2.4622,'col':'#809dbc'},
]
planets,trails,names = [],[],[]
easing = dpl.easeInSine()
Then, we loop over the planets and create them using Circle, Arc and text to display the planet, its orbit and its name:
for i,planet_info in enumerate(planet_infos):
d = planet_info['d']
r = planet_info['r']
c = planet_info['col']
n = planet_info['name']
r = np.sqrt(r)/2
omega = d**(-3/2)*180*100
name_offset = (i+1)/1.5
name_size = (i+1)*2
planet = dpl.Circle(xy=(d,0),radius=r,fc=c,zorder=2)
trail = dpl.Arc(width=2*d,height=2*d,xy=(0,0),theta1=-30,theta2=0,lw=3,ec=c,zorder=1)
name = dpl.text(x=d,y=name_offset,string=n,fc='w',lw=0,fontsize=name_size,ha='center',va='center',alpha=0)
planet.rotate(start_angle=0,end_angle= omega,center=(0,0) ,duration=360,easing=easing)
trail.rotate( start_angle=0,end_angle= omega,center=(0,0) ,duration=360,easing=easing)
name.rotate( start_angle=0,end_angle=-omega ,duration=360,easing=easing)
name.rotate( start_angle=0,end_angle= omega,center=(0,name_offset),duration=360,easing=easing)
name.show(duration=30,delay=i*10)
name.hide(duration=30,delay=280)
planets.append(planet)
trails.append(trail)
names.append(name)
Finally, we create an axis_track() and an axis_zoom() animation to follow Saturn and zoom in on it.
We then render the frames and save the video.
a1 = dpl.axis_track(planets[5],duration=360)
a2 = dpl.axis_zoom(zoom=5,duration=360)
tl.animate((sun,*planets,*trails,*names,a1,a2))
tl.save_video('../../_static/examples/solar_system.mp4')