Untitled
unknown
plain_text
2 years ago
2.5 kB
4
Indexable
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation dictionnaire_planetes = { 'Terre': {"masse": 5.972e24, 'périhélie': 147098291000, 'excentricite': 0.0167, 'longueur_demi_axe': 149598023000, 'periode': 365.25 * 24 * 60 ** 2}, 'Venus': {"masse": 4.867e24, 'périhélie': 107476170000, 'excentricite': 0.007, 'longueur_demi_axe': 108209500000, 'periode': 224.7 * 24 * 60 ** 2}, 'Mercure': {"masse": 3.285e23, 'périhélie': 46001009000, 'excentricite': 0.21, 'longueur_demi_axe': 57909050000, 'periode': 88.0 * 24 * 60 ** 2}, 'Mars': {"masse": 6.4185e23, 'périhélie': 206655000000, 'excentricite': 0.09339, 'longueur_demi_axe': 227944000000, 'periode': 686.9 * 24 * 60 ** 2}, 'Jupiter': {"masse": 1.898e27, 'périhélie': 740680000000, 'excentricite': 0.048, 'longueur_demi_axe': 778340000000, 'periode': 4332 * 24 * 60 ** 2}, 'Saturne': {"masse": 5.684e26, 'périhélie': 1349800000000, 'excentricite': 0.0539, 'longueur_demi_axe': 1426700000000, 'periode': 10754 * 24 * 60 ** 2}, 'Neptune': {"masse": 1.024e26, 'périhélie': 4459800000000, 'excentricite': 0.00859, 'longueur_demi_axe': 4498400000000, 'periode': 60216 * 24 * 60 ** 2}, 'Uranus': {"masse": 8.681e25, 'périhélie': 2735000000000, 'excentricite': 0.0047, 'longueur_demi_axe': 2870700000000, 'periode': 30698 * 24 * 60 ** 2} } fig, ax = plt.subplots() ax.set_xlim(-5e12, 5e12) ax.set_ylim(-5e12, 5e12) ellipses = {} scatter_points = {} for planete, info in dictionnaire_planetes.items(): ellipse = plt.Circle((0, 0), info['longueur_demi_axe'], ec='black', fc='none') scatter = ax.scatter([], [], s=30) ax.add_artist(ellipse) ellipses[planete] = ellipse scatter_points[planete] = scatter def init(): return [] def update(frame): t = frame * 10000000 # Ajustez la vitesse de l'animation ici for planete, info in dictionnaire_planetes.items(): a = info['longueur_demi_axe'] e = info['excentricite'] periode = info['periode'] peri = 2 * np.pi * (t % periode) / periode x = a * (np.cos(peri) - e) y = a * np.sqrt(1 - e**2) * np.sin(peri) scatter_points[planete].set_offsets([x, y]) return [] ani = animation.FuncAnimation(fig, update, frames=1000, init_func=init, blit=True) plt.axis('off') plt.show()
Editor is loading...