from manim import *
narration_segments = [
"Gravity is a fundamental force that attracts two bodies towards each other.",
"Isaac Newton formulated the law of universal gravitation as F equals G times the product of masses divided by the square of the distance.",
"This force keeps planets in orbit around the sun and causes objects to fall to the ground."
]
# Durations of the audio segments in seconds
AUDIO1_DURATION = 5
AUDIO2_DURATION = 7
AUDIO3_DURATION = 6
class GravityScene(Scene):
def construct(self):
# Segment 1
title1 = Text("What is Gravity?", font_size=48)
definition = Text(
"Gravity is a fundamental force\nthat attracts two bodies towards each other.",
font_size=36
).next_to(title1, DOWN, buff=0.8)
self.add(title1, definition)
self.add_sound("audio1.mp3")
self.wait(AUDIO1_DURATION)
self.clear() # Clean up before next segment
# Segment 2
title2 = Text("Newton's Law of Universal Gravitation", font_size=42)
formula = MathTex(
r"F = G \frac{m_1 m_2}{r^2}",
font_size=48
).next_to(title2, DOWN, buff=1)
explanation = Text(
"Force equals gravitational constant G\n"
"times the product of masses divided by the square of the distance.",
font_size=36
).next_to(formula, DOWN, buff=0.8)
self.add(title2, formula, explanation)
self.add_sound("audio2.mp3")
self.wait(AUDIO2_DURATION)
self.clear() # Clean up before next segment
# Segment 3
title3 = Text("Gravity in Action", font_size=48)
self.add(title3)
self.wait(1)
# Create sun and earth
sun = Circle(radius=1.2, color=YELLOW, fill_opacity=1)
sun_text = Text("Sun", font_size=36).next_to(sun, DOWN)
earth = Circle(radius=0.6, color=BLUE, fill_opacity=1)
earth_text = Text("Earth", font_size=36).next_to(earth, DOWN)
# Position sun on left, earth on right
sun.to_edge(LEFT, buff=1.5).shift(DOWN*0.5)
earth.to_edge(RIGHT, buff=1.5).shift(DOWN*0.5)
# Arrow representing gravitational force
force_arrow = Arrow(
start=earth.get_left(),
end=sun.get_right(),
buff=0.1,
color=RED,
stroke_width=6
)
force_label = MathTex(r"\vec{F}", font_size=36, color=RED).next_to(force_arrow.get_center(), UP)
# Earth orbit path
orbit = Circle(radius=3, color=GRAY, stroke_width=2).move_to(sun.get_center())
# Add all objects
self.add(sun, sun_text, earth, earth_text, orbit)
self.play(Create(force_arrow), Write(force_label))
self.add_sound("audio3.mp3")
self.wait(AUDIO3_DURATION)
self.clear()