from manim import *
class NewtonsLawOfGravity(Scene):
def construct(self):
# Title
title = Text("Newton's Law of Gravity").scale(1.2)
self.play(Write(title))
self.wait(2)
self.play(FadeOut(title))
# Display the formula
formula = MathTex(
"F = G \\frac{m_1 m_2}{r^2}"
).scale(1.5)
self.play(Write(formula))
self.wait(3)
self.play(FadeOut(formula))
# Introduce the two masses and the force vector
m1 = Circle(radius=0.7, color=BLUE, fill_opacity=0.7)
m1_label = Tex("m_1").next_to(m1, DOWN)
m2 = Circle(radius=0.5, color=RED, fill_opacity=0.7)
m2_label = Tex("m_2").next_to(m2, DOWN)
# Position the masses with enough distance
m1.to_edge(LEFT, buff=1.5)
m2.to_edge(RIGHT, buff=1.5)
self.play(FadeIn(m1), Write(m1_label))
self.play(FadeIn(m2), Write(m2_label))
self.wait(1)
# Label distance r between centers
r_line = Line(m1.get_right(), m2.get_left(), color=YELLOW)
r_label = Tex("r").next_to(r_line, UP, buff=0.1)
self.play(Create(r_line), Write(r_label))
self.wait(1)
# Draw force vectors between masses: F on m1 points to m2, F on m2 points to m1
# Arrows representing attraction forces
force_m1 = Arrow(m1.get_right(), m2.get_left(), buff=0.1, color=GREEN)
force_m1_label = Tex("\\vec{F}_{12}").set_color(GREEN).next_to(force_m1, UP, buff=0.1)
force_m2 = Arrow(m2.get_left(), m1.get_right(), buff=0.1, color=GREEN)
force_m2_label = Tex("\\vec{F}_{21}").set_color(GREEN).next_to(force_m2, DOWN, buff=0.1)
self.play(GrowArrow(force_m1), Write(force_m1_label))
self.wait(1)
self.play(GrowArrow(force_m2), Write(force_m2_label))
self.wait(2)
# Clean up the scene before next part
self.play(
FadeOut(m1), FadeOut(m1_label),
FadeOut(m2), FadeOut(m2_label),
FadeOut(r_line), FadeOut(r_label),
FadeOut(force_m1), FadeOut(force_m1_label),
FadeOut(force_m2), FadeOut(force_m2_label),
)
self.wait(1)
# Show a short explanation text
explanation = Tex(
"The gravitational force between two masses is attractive,",
" proportional to the product of their masses,",
" and inversely proportional to the square of the distance between them."
)
explanation.set_width(FRAME_WIDTH * 0.8)
explanation.to_edge(UP)
self.play(Write(explanation[0]))
self.wait(2)
self.play(Write(explanation[1]), run_time=2)
self.wait(2)
self.play(Write(explanation[2]), run_time=3)
self.wait(3)
self.play(FadeOut(explanation))