Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Final changes before de chapter 1

Grant Sanderson4019a80c4b70
diff --git a/active_projects/ode/all_part1_scenes.py b/active_projects/ode/all_part1_scenes.py
index 3ab32a2a8..6187244b2 100644
--- a/active_projects/ode/all_part1_scenes.py
+++ b/active_projects/ode/all_part1_scenes.py
@@ -6,6 +6,7 @@ from active_projects.ode.part1.wordy_scenes import *
OUTPUT_DIRECTORY = "ode/part1"
ALL_SCENE_CLASSES = [
+ WhenChangeIsEasier,
VectorFieldTest,
IntroducePendulum,
MultiplePendulumsOverlayed,
@@ -30,10 +31,14 @@ ALL_SCENE_CLASSES = [
# Something...
ShowSimpleTrajectory,
SimpleProjectileEquation,
+ SimpleProjectileEquationVGraphFreedom,
ShowGravityAcceleration,
+ UniversalGravityLawSymbols,
+ ExampleTypicalODE,
AnalyzePendulumForce,
ShowSineValues,
BuildUpEquation,
+ AirResistanceBrace,
ShowDerivativeVideo,
SubtleAirCurrents,
SimpleDampenedPendulum,
@@ -50,6 +55,7 @@ ALL_SCENE_CLASSES = [
SoWhatIsThetaThen,
ReallyHardToSolve,
ReasonForSolution,
+ PhysicistPhaseSpace,
GleickQuote,
SpectrumOfStartingStates,
WritePhaseFlow,
@@ -97,4 +103,5 @@ ALL_SCENE_CLASSES = [
ChaosTitle,
RevisitQuote,
EndScreen,
+ Thumbnail,
]
diff --git a/active_projects/ode/part1/phase_space.py b/active_projects/ode/part1/phase_space.py
index ea4ad0c90..1a6c7a8f1 100644
--- a/active_projects/ode/part1/phase_space.py
+++ b/active_projects/ode/part1/phase_space.py
@@ -2007,3 +2007,67 @@ class ManyStepsFromDifferentStartingPoints(TakeManyTinySteps):
run_time=5,
rate_func=linear,
)
+
+
+class Thumbnail(IntroduceVectorField):
+ CONFIG = {
+ "vector_field_config": {
+ "delta_x": 1,
+ "delta_y": 1,
+ "max_magnitude": 5,
+ "length_func": lambda norm: 0.75 * sigmoid(norm),
+ }
+ }
+
+ def construct(self):
+ self.initialize_plane()
+ self.initialize_vector_field()
+
+ field = self.vector_field
+ field.set_stroke(width=5)
+
+ title = TextMobject("Differential\\\\", "equations")
+ title.space_out_submobjects(0.8)
+ # title.scale(3)
+ title.set_width(FRAME_WIDTH - 3)
+ # title.to_edge(UP)
+ # title[1].to_edge(DOWN)
+
+ subtitle = TextMobject("Studying the unsolvable")
+ subtitle.set_width(FRAME_WIDTH - 1)
+ subtitle.set_color(WHITE)
+ subtitle.to_edge(DOWN, buff=1)
+
+ # title.center()
+ title.to_edge(UP, buff=1)
+ title.add(subtitle)
+ # title.set_stroke(BLACK, 15, background=True)
+ # title.add_background_rectangle_to_submobjects(opacity=0.5)
+ title.set_stroke(BLACK, 15, background=True)
+ subtitle.set_stroke(RED, 2, background=True)
+ # for part in title:
+ # part[0].set_fill(opacity=0.25)
+ # part[0].set_stroke(width=0)
+ black_parts = VGroup()
+ for mob in title.family_members_with_points():
+ for sp in mob.get_subpaths():
+ new_mob = VMobject()
+ new_mob.set_points(sp)
+ new_mob.set_fill(BLACK, 0.25)
+ new_mob.set_stroke(width=0)
+ black_parts.add(new_mob)
+
+ for vect in field:
+ for mob in title.family_members_with_points():
+ for p in [vect.get_start(), vect.get_end()]:
+ x, y = p[:2]
+ x0, y0 = mob.get_corner(DL)[:2]
+ x1, y1 = mob.get_corner(UR)[:2]
+ if x0 < x < x1 and y0 < y < y1:
+ vect.set_opacity(0.25)
+ vect.tip.set_stroke(width=0)
+
+ self.add(self.plane)
+ self.add(field)
+ self.add(black_parts)
+ self.add(title)
diff --git a/active_projects/ode/part1/pi_scenes.py b/active_projects/ode/part1/pi_scenes.py
index 09066905c..23a4232dd 100644
--- a/active_projects/ode/part1/pi_scenes.py
+++ b/active_projects/ode/part1/pi_scenes.py
@@ -230,6 +230,58 @@ class ProveTeacherWrong(TeacherStudentsScene):
self.wait(8)
+class PhysicistPhaseSpace(PiCreatureScene):
+ def construct(self):
+ physy = self.pi_creature
+ name = TextMobject("Physicist")
+ name.scale(1.5)
+ name.to_corner(DL, buff=MED_SMALL_BUFF)
+ physy.next_to(name, UP, SMALL_BUFF)
+ VGroup(name, physy).shift_onto_screen()
+
+ axes = Axes(
+ x_min=-1,
+ x_max=10,
+ y_min=-1,
+ y_max=7,
+ )
+ axes.set_height(6)
+ axes.next_to(physy, RIGHT)
+ axes.to_edge(UP)
+ axes.set_stroke(width=1)
+ x_label = TextMobject("Position")
+ x_label.next_to(axes.x_axis.get_right(), UP)
+ y_label = TextMobject("Momentum")
+ y_label.next_to(axes.y_axis.get_top(), RIGHT)
+
+ title = TextMobject("Phase space")
+ title.scale(1.5)
+ title.set_color(YELLOW)
+ title.move_to(axes)
+
+ self.add(name, physy)
+
+ self.play(
+ physy.change, "angry",
+ Write(axes),
+ FadeInFromDown(title)
+ )
+ self.wait(2)
+ self.play(
+ GrowFromPoint(x_label, physy.get_corner(UR)),
+ physy.change, "raise_right_hand",
+ axes.x_axis.get_right()
+ )
+ self.play(
+ GrowFromPoint(y_label, physy.get_corner(UR)),
+ physy.look_at, axes.y_axis.get_top(),
+ )
+ self.wait(3)
+
+ def create_pi_creature(self):
+ return PiCreature(color=GREY).to_corner(DL)
+
+
class AskAboutActuallySolving(TeacherStudentsScene):
def construct(self):
ode = get_ode()
@@ -239,7 +291,7 @@ class AskAboutActuallySolving(TeacherStudentsScene):
self.student_says(
"Yeah yeah, but how do\\\\"
- "you acutally \\emph{solve} it?",
+ "you actually \\emph{solve} it?",
student_index=1,
target_mode="sassy",
added_anims=[morty.change, "thinking"],
diff --git a/active_projects/ode/part1/staging.py b/active_projects/ode/part1/staging.py
index 8fcb852ae..1deb25b05 100644
--- a/active_projects/ode/part1/staging.py
+++ b/active_projects/ode/part1/staging.py
@@ -69,6 +69,20 @@ class ShowSquare(ShowRect):
}
+class WhenChangeIsEasier(Scene):
+ def construct(self):
+ pass
+
+
+class AirResistanceBrace(Scene):
+ def construct(self):
+ brace = Brace(Line(ORIGIN, RIGHT), DOWN)
+ word = TextMobject("Air resistance")
+ word.next_to(brace, DOWN)
+ self.play(GrowFromCenter(brace), FadeInFrom(word, UP))
+ self.wait()
+
+
class PeriodFormula(Scene):
def construct(self):
formula = get_period_formula()
@@ -1024,6 +1038,195 @@ class SimpleProjectileEquation(ShowGravityAcceleration):
self.wait()
+class SimpleProjectileEquationVGraphFreedom(SimpleProjectileEquation):
+ def construct(self):
+ self.add_axes()
+ self.setup_trajectory()
+ self.clear()
+ v_graph = self.v_graph
+ self.t_tracker.set_value(5)
+ v_graph.update()
+ v_graph.clear_updaters()
+ self.add(v_graph)
+ self.play(v_graph.shift, 5 * DOWN, run_time=2)
+ self.play(v_graph.shift, 5 * UP, run_time=2)
+
+
+class UniversalGravityLawSymbols(Scene):
+ def construct(self):
+ x1_tex = "\\vec{\\textbf{x}}_1"
+ x2_tex = "\\vec{\\textbf{x}}_2"
+ a1_tex = "\\vec{\\textbf{a}}_1"
+ new_brown = interpolate_color(LIGHT_GREY, LIGHT_BROWN, 0.5)
+ law = TexMobject(
+ "F_1", "=", "m_1", a1_tex, "=",
+ "G", "m_1", "m_2",
+ "\\left({", x2_tex, "-", x1_tex, "\\over",
+ "||", x2_tex, "-", x1_tex, "||", "}\\right)",
+ "\\left({", "1", "\\over",
+ "||", x2_tex, "-", x1_tex, "||^2", "}\\right)",
+ tex_to_color_map={
+ x1_tex: BLUE_C,
+ "m_1": BLUE_C,
+ x2_tex: new_brown,
+ "m_2": new_brown,
+ a1_tex: YELLOW,
+ }
+ )
+ law.to_edge(UP)
+
+ force = law[:4]
+ constants = law[4:8]
+ unit_vect = law[8:19]
+ inverse_square = law[19:]
+ parts = VGroup(
+ force, unit_vect, inverse_square
+ )
+
+ words = VGroup(
+ TextMobject("Force on\\\\mass 1"),
+ TextMobject("Unit vector\\\\towards mass 2"),
+ TextMobject("Inverse square\\\\law"),
+ )
+
+ self.add(law)
+
+ braces = VGroup()
+ rects = VGroup()
+ for part, word in zip(parts, words):
+ brace = Brace(part, DOWN)
+ word.scale(0.8)
+ word.next_to(brace, DOWN)
+ rect = SurroundingRectangle(part)
+ rect.set_stroke(YELLOW, 1)
+ braces.add(brace)
+ rects.add(rect)
+
+ self.play(
+ ShowCreationThenFadeOut(rects[0]),
+ GrowFromCenter(braces[0]),
+ FadeInFrom(words[0], UP)
+ )
+ self.wait()
+ self.play(
+ ShowCreationThenFadeOut(rects[1]),
+ GrowFromCenter(braces[1]),
+ FadeInFrom(words[1], UP)
+ )
+ self.wait()
+ self.play(
+ ShowCreationThenFadeOut(rects[2]),
+ TransformFromCopy(*braces[1:3]),
+ FadeInFrom(words[2], UP),
+ )
+ self.wait()
+
+ # Position derivative
+ v1_tex = "\\vec{\\textbf{v}}_1"
+ kw = {
+ "tex_to_color_map": {
+ x1_tex: BLUE_C,
+ v1_tex: RED,
+ }
+ }
+ x_deriv = TexMobject(
+ "{d", x1_tex, "\\over", "dt}", "=", v1_tex, **kw
+ )
+ x_deriv.to_corner(UL)
+ v_deriv = TexMobject(
+ "{d", v1_tex, "\\over", "dt}", "=", **kw
+ )
+
+ # Make way
+ law.generate_target()
+ lt = law.target
+ lt.to_edge(RIGHT)
+ lt[6].fade(1)
+ lt[:6].align_to(lt[6], RIGHT)
+ lt[:3].fade(1)
+ v_deriv.next_to(lt[3], LEFT)
+
+ self.play(
+ FadeInFromDown(x_deriv),
+ MoveToTarget(law),
+ braces[1:].align_to, lt, RIGHT,
+ MaintainPositionRelativeTo(words[1:], braces[1:]),
+ FadeOut(words[0]),
+ FadeOut(braces[0]),
+ )
+ self.play(ShowCreationThenFadeAround(x_deriv))
+
+ self.play(
+ TransformFromCopy(
+ x_deriv.get_part_by_tex(v1_tex),
+ v_deriv.get_part_by_tex(v1_tex),
+ ),
+ Write(VGroup(*filter(
+ lambda m: m is not v_deriv.get_part_by_tex(v1_tex),
+ v_deriv,
+ )))
+ )
+
+ x_parts = law.get_parts_by_tex(x1_tex)
+ self.play(
+ TransformFromCopy(
+ x_deriv.get_parts_by_tex(x1_tex),
+ x_parts.copy(),
+ remover=True,
+ path_arc=30 * DEGREES,
+ )
+ )
+ self.play(
+ LaggedStartMap(
+ ShowCreationThenFadeAround,
+ x_parts
+ )
+ )
+ self.wait()
+
+
+class ExampleTypicalODE(TeacherStudentsScene):
+ def construct(self):
+ examples = VGroup(
+ TexMobject(
+ "{\\dot x}(t) = k{x}(t)",
+ tex_to_color_map={
+ "{\\dot x}": BLUE,
+ "{x}": BLUE,
+ },
+ ),
+ get_ode(),
+ TexMobject(
+ "{\\partial T", "\\over", "\\partial t} = ",
+ "{\\partial^2 T", "\\over", "\\partial x^2}", "+",
+ "{\\partial^2 T", "\\over", "\\partial y^2}", "+",
+ "{\\partial^2 T", "\\over", "\\partial z^2}",
+ tex_to_color_map={
+ "T": RED,
+ }
+ ),
+ )
+ examples[1].get_parts_by_tex("theta").set_color(GREEN)
+ examples.arrange(DOWN, buff=MED_LARGE_BUFF)
+ examples.to_edge(UP)
+
+ self.play(
+ FadeInFrom(examples[0], UP),
+ self.teacher.change, "raise_right_hand",
+ )
+ self.play(
+ FadeInFrom(examples[1], UP),
+ self.get_student_changes(
+ *3 * ["pondering"],
+ look_at_arg=examples,
+ ),
+ )
+ self.play(
+ FadeInFrom(examples[2], UP)
+ )
+ self.wait(5)
+
+
class ShowDerivativeVideo(Scene):
def construct(self):
title = TextMobject("Essence of", "Calculus")
diff --git a/active_projects/ode/part1/wordy_scenes.py b/active_projects/ode/part1/wordy_scenes.py
index 8529bc67b..a6c53ed73 100644
--- a/active_projects/ode/part1/wordy_scenes.py
+++ b/active_projects/ode/part1/wordy_scenes.py
@@ -667,7 +667,7 @@ class JumpToThisPoint(Scene):
class ChaosTitle(Scene):
def construct(self):
- title = TextMobject("Chaos theorey")
+ title = TextMobject("Chaos theory")
title.scale(1.5)
title.to_edge(UP)
line = Line(LEFT, RIGHT)