{ "cells": [ { "cell_type": "markdown", "id": "8bf0c3d7", "metadata": {}, "source": [ "# Solar system\n", "\n", "This example uses the `rotate()` animation to animate `Circle` plot objects, and follows a planet with `axis_track()`.\n", "\n", "We first create our timeline with our styling:" ] }, { "cell_type": "code", "execution_count": null, "id": "b8ecc773", "metadata": {}, "outputs": [], "source": [ "import diplotocus as dpl\n", "import numpy as np\n", "\n", "tl = dpl.Timeline(xlim=(-40,40),ylim=(-40,40),figsize=(5,5),noaxis=True,fig_color='k',bbox_inches='tight')" ] }, { "cell_type": "markdown", "id": "24fd520c", "metadata": {}, "source": [ "Then, we create the Sun and define the planets' properties:" ] }, { "cell_type": "code", "execution_count": null, "id": "96cf2ebe", "metadata": {}, "outputs": [], "source": [ "sun = dpl.Circle(xy=(0,0),radius=1,fc='yellow')\n", "sun.plot(360)\n", "\n", "planet_infos = [\n", " {'name':'Mercury','d':0.320,'r':0.2440,'col':'#bfbdbc'},\n", " {'name':'Venus' ,'d':0.720,'r':0.6052,'col':'#d4b496'},\n", " {'name':'Earth' ,'d':1.000,'r':0.6371,'col':'#6a87a5'},\n", " {'name':'Mars' ,'d':1.400,'r':0.3390,'col':'#e38266'},\n", " {'name':'Jupiter','d':5.260,'r':6.9911,'col':'#bdb19e'},\n", " {'name':'Saturn' ,'d':9.480,'r':5.8232,'col':'#d4b880'},\n", " {'name':'Uranus' ,'d':19.47,'r':2.5362,'col':'#9dbabd'},\n", " {'name':'Neptune','d':29.88,'r':2.4622,'col':'#809dbc'},\n", "]\n", "planets,trails,names = [],[],[]\n", "easing = dpl.easeInSine()" ] }, { "cell_type": "markdown", "id": "12165f98", "metadata": {}, "source": [ "Then, we loop over the planets and create them using `Circle`, `Arc` and `text` to display the planet, its orbit and its name:" ] }, { "cell_type": "code", "execution_count": null, "id": "4e2d91a0", "metadata": {}, "outputs": [], "source": [ "for i,planet_info in enumerate(planet_infos):\n", " d = planet_info['d']\n", " r = planet_info['r']\n", " c = planet_info['col']\n", " n = planet_info['name']\n", " r = np.sqrt(r)/2\n", " omega = d**(-3/2)*180*100\n", " name_offset = (i+1)/1.5\n", " name_size = (i+1)*2\n", "\n", " planet = dpl.Circle(xy=(d,0),radius=r,fc=c,zorder=2)\n", " trail = dpl.Arc(width=2*d,height=2*d,xy=(0,0),theta1=-30,theta2=0,lw=3,ec=c,zorder=1)\n", " name = dpl.text(x=d,y=name_offset,string=n,fc='w',lw=0,fontsize=name_size,ha='center',va='center',alpha=0)\n", "\n", " planet.rotate(start_angle=0,end_angle= omega,center=(0,0) ,duration=360,easing=easing)\n", " trail.rotate( start_angle=0,end_angle= omega,center=(0,0) ,duration=360,easing=easing)\n", " name.rotate( start_angle=0,end_angle=-omega ,duration=360,easing=easing)\n", " name.rotate( start_angle=0,end_angle= omega,center=(0,name_offset),duration=360,easing=easing)\n", " name.show(duration=30,delay=i*10)\n", " name.hide(duration=30,delay=280)\n", " \n", " planets.append(planet)\n", " trails.append(trail)\n", " names.append(name)" ] }, { "cell_type": "markdown", "id": "4b125c81", "metadata": {}, "source": [ "Finally, we create an `axis_track()` and an `axis_zoom()` animation to follow Saturn and zoom in on it.\n", "\n", "We then render the frames and save the video." ] }, { "cell_type": "code", "execution_count": null, "id": "0b758ac5", "metadata": {}, "outputs": [], "source": [ "a1 = dpl.axis_track(planets[5],duration=360)\n", "a2 = dpl.axis_zoom(zoom=5,duration=360)\n", "\n", "tl.animate((sun,*planets,*trails,*names,a1,a2))\n", "\n", "tl.save_video('../../_static/examples/solar_system.mp4')" ] }, { "cell_type": "code", "execution_count": 25, "id": "f5077e4e", "metadata": { "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "\n", " \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import HTML, display\n", "display(HTML(\"\"\"\n", " \n", "\"\"\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.3" } }, "nbformat": 4, "nbformat_minor": 5 }