Last active
June 8, 2023 17:20
-
-
Save jbwhit/a8c92ad63175874dc4287d85ba59a53e to your computer and use it in GitHub Desktop.
This code creates this video here: https://youtu.be/g5QsoVxFSx0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from manim import * | |
class SolarSystem(ThreeDScene): | |
def construct(self): | |
# Set the initial camera position | |
self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES) | |
colors = { | |
"mercury": "#999393", | |
"venus": "#C0BDB4", | |
"earth": "#60647B", | |
"mars": "#A0522D", | |
} | |
radii = { | |
"jupiter": 1.025, | |
"saturn": 0.8535714285714285, | |
"uranus": 0.37142857142857144, | |
"neptune": 0.3607142857142857, | |
"earth": 0.09321428571428571, | |
"venus": 0.08857142857142856, | |
"mars": 0.04964285714285714, | |
"mercury": 0.03571428571428571, | |
} | |
# Import data | |
planets = {} | |
for planet in [ | |
"mercury", | |
"venus", | |
"earth", | |
"mars", | |
]: | |
data = pd.read_parquet(f"{planet}-short.parquet") | |
planets[planet] = Sphere( | |
radius=radii[planet], | |
color=colors[planet], | |
fill_color=colors[planet], | |
stroke_color=colors[planet], | |
).move_to([data["x"].array[0], data["y"].array[0], data["z"].array[0]]) | |
planets[planet + "_data"] = data | |
self.add(planets[planet]) | |
sun = Sphere( | |
radius=0.10, | |
color="#FFF5ED", | |
fill_color="#FFF5ED", | |
stroke_color="#FFF5ED", | |
) | |
self.add(sun) | |
# Animate planets | |
for i in range(1, 500, 1): # increment of 100 for speeding up | |
for planet, object in planets.items(): | |
if isinstance(object, Sphere): | |
self.play( | |
object.animate.move_to( | |
[ | |
planets[planet + "_data"]["x"].array[i], | |
planets[planet + "_data"]["y"].array[i], | |
planets[planet + "_data"]["z"].array[i], | |
] | |
), | |
run_time=0.01, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment