Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Pile of ode scenes made while editing

Grant Sandersone3a40388ec8f
diff --git a/active_projects/ode/all_part1_scenes.py b/active_projects/ode/all_part1_scenes.py
index a8a13ebd7..3ab32a2a8 100644
--- a/active_projects/ode/all_part1_scenes.py
+++ b/active_projects/ode/all_part1_scenes.py
@@ -28,6 +28,8 @@ ALL_SCENE_CLASSES = [
RabbitFoxPopulations,
RabbitFoxEquation,
# Something...
+ ShowSimpleTrajectory,
+ SimpleProjectileEquation,
ShowGravityAcceleration,
AnalyzePendulumForce,
ShowSineValues,
@@ -52,6 +54,13 @@ ALL_SCENE_CLASSES = [
SpectrumOfStartingStates,
WritePhaseFlow,
AskAboutStability,
+ LoveExample,
+ PassageOfTime,
+ LovePhaseSpace,
+ ComparePhysicsToLove,
+ FramesComparingPhysicsToLove,
+ SetupToTakingManyTinySteps,
+ ShowClutterPrevention,
# VisualizeHeightSlopeCurvature,
VisualizeStates,
ReferencePiCollisionStateSpaces,
@@ -81,6 +90,7 @@ ALL_SCENE_CLASSES = [
InaccurateComputation,
HungerForExactness,
ShowRect,
+ ShowSquare,
JumpToThisPoint,
ThreeBodyEquation,
ItGetsWorse,
diff --git a/active_projects/ode/part1/phase_space.py b/active_projects/ode/part1/phase_space.py
index 40d69d304..ea4ad0c90 100644
--- a/active_projects/ode/part1/phase_space.py
+++ b/active_projects/ode/part1/phase_space.py
@@ -1025,7 +1025,7 @@ class ShowHighVelocityCase(ShowPendulumPhaseFlow, MovingCameraScene):
]
self.play(*anims, run_time=total_time)
- def get_trajectory(self, start_point, time, dt=0.1, added_steps=1000):
+ def get_trajectory(self, start_point, time, dt=0.1, added_steps=100):
field = self.vector_field
traj = VMobject()
traj.start_new_path(start_point)
@@ -1373,10 +1373,261 @@ class AskAboutStability(ShowHighVelocityCase):
self.wait()
+class LovePhaseSpace(ShowHighVelocityCase):
+ CONFIG = {
+ "vector_field_config": {
+ "max_magnitude": 4,
+ # "delta_x": 2,
+ # "delta_y": 2,
+ },
+ "a": 0.5,
+ "b": 0.3,
+ "mu": 0.2,
+ }
+
+ def construct(self):
+ self.setup_plane()
+ self.add_equations()
+ self.show_vector_field()
+ self.show_example_trajectories()
+ self.add_resistance_term()
+ self.show_new_trajectories()
+
+ def setup_plane(self):
+ plane = self.plane = NumberPlane()
+ plane.add_coordinates()
+ self.add(plane)
+
+ h1, h2 = hearts = VGroup(*[
+ get_heart_var(i)
+ for i in (1, 2)
+ ])
+ hearts.scale(0.5)
+ hearts.set_stroke(BLACK, 5, background=True)
+
+ h1.next_to(plane.x_axis.get_right(), UL, SMALL_BUFF)
+ h2.next_to(plane.y_axis.get_top(), DR, SMALL_BUFF)
+ for h in hearts:
+ h.shift_onto_screen(buff=MED_SMALL_BUFF)
+ plane.add(hearts)
+
+ self.axis_hearts = hearts
+
+ def add_equations(self):
+ equations = VGroup(
+ get_love_equation1(),
+ get_love_equation2(),
+ )
+ equations.scale(0.5)
+ equations.arrange(
+ DOWN,
+ aligned_edge=LEFT,
+ buff=MED_LARGE_BUFF
+ )
+ equations.to_corner(UL)
+ equations.add_background_rectangle_to_submobjects()
+ # for eq in equations:
+ # eq.add_background_rectangle_to_submobjects()
+
+ self.add(equations)
+ self.equations = equations
+
+ def show_vector_field(self):
+ field = VectorField(
+ lambda p: np.array([
+ self.a * p[1], -self.b * p[0], 0
+ ]),
+ **self.vector_field_config
+ )
+ field.sort(get_norm)
+ x_range = np.arange(-7, 7.5, 0.5)
+ y_range = np.arange(-4, 4.5, 0.5)
+ x_axis_arrows = VGroup(*[
+ field.get_vector([x, 0, 0])
+ for x in x_range
+ ])
+ y_axis_arrows = VGroup(*[
+ field.get_vector([0, y, 0])
+ for y in y_range
+ ])
+ axis_arrows = VGroup(*x_axis_arrows, *y_axis_arrows)
+
+ axis_arrows.save_state()
+ for arrow in axis_arrows:
+ real_len = get_norm(field.func(arrow.get_start()))
+ arrow.scale(
+ 0.5 * real_len / arrow.get_length(),
+ about_point=arrow.get_start()
+ )
+
+ self.play(
+ LaggedStartMap(GrowArrow, x_axis_arrows),
+ )
+ self.play(
+ LaggedStartMap(GrowArrow, y_axis_arrows),
+ )
+ self.wait()
+ self.add(field, self.equations, self.axis_hearts)
+ self.play(
+ axis_arrows.restore,
+ # axis_arrows.fade, 1,
+ ShowCreation(field),
+ run_time=3
+ )
+ self.remove(axis_arrows)
+ self.wait()
+
+ self.field = self.vector_field = field
+
+ def show_example_trajectories(self):
+ n_points = 20
+ total_time = 30
+
+ start_points = self.start_points = [
+ 2.5 * np.random.random() * rotate_vector(
+ RIGHT,
+ TAU * np.random.random()
+ )
+ for x in range(n_points)
+ ]
+ dots = VGroup(*[Dot(sp) for sp in start_points])
+ dots.set_color_by_gradient(BLUE, WHITE)
+
+ words = TextMobject("Possible initial\\\\", "conditions")
+ words.scale(1.5)
+ words.add_background_rectangle_to_submobjects()
+ words.set_stroke(BLACK, 5, background=True)
+ words.shift(FRAME_WIDTH * RIGHT / 4)
+ words.to_edge(UP)
+ self.possibility_words = words
+
+ self.play(
+ LaggedStartMap(
+ FadeInFromLarge, dots,
+ lambda m: (m, 5)
+ ),
+ FadeInFromDown(words)
+ )
+
+ trajs = VGroup(*[
+ self.get_trajectory(
+ sp, total_time,
+ added_steps=10,
+ )
+ for sp in start_points
+ ])
+ trajs.set_color_by_gradient(BLUE, WHITE)
+
+ dots.trajs = trajs
+
+ def update_dots(ds):
+ for d, t in zip(ds, ds.trajs):
+ d.move_to(t.points[-1])
+ dots.add_updater(update_dots)
+
+ self.add(trajs, dots)
+ self.play(
+ ShowCreation(
+ trajs,
+ lag_ratio=0,
+ run_time=10,
+ rate_func=linear,
+ )
+ )
+
+ self.trajs = trajs
+ self.dots = dots
+
+ def add_resistance_term(self):
+ added_term = VGroup(
+ TexMobject("-\\mu"),
+ get_heart_var(2).scale(0.5),
+ )
+ added_term.arrange(RIGHT, buff=SMALL_BUFF)
+ equation2 = self.equations[1]
+ equation2.generate_target()
+ br, deriv, eq, neg_b, h1 = equation2.target
+ added_term.next_to(eq, RIGHT, SMALL_BUFF)
+ added_term.align_to(h1, DOWN)
+ VGroup(neg_b, h1).next_to(
+ added_term, RIGHT, SMALL_BUFF,
+ aligned_edge=DOWN,
+ )
+ br.stretch(1.2, 0, about_edge=LEFT)
+
+ brace = Brace(added_term, DOWN, buff=SMALL_BUFF)
+ words = brace.get_text(
+ "``Resistance'' term"
+ )
+ words.set_stroke(BLACK, 5, background=True)
+ words.add_background_rectangle()
+
+ self.add(equation2, added_term)
+ self.play(
+ MoveToTarget(equation2),
+ FadeInFromDown(added_term),
+ GrowFromCenter(brace),
+ Write(words),
+ )
+ self.play(ShowCreationThenFadeAround(added_term))
+
+ equation2.add(added_term, brace, words)
+
+ def show_new_trajectories(self):
+ dots = self.dots
+ trajs = self.trajs
+ field = self.field
+
+ new_field = VectorField(
+ lambda p: np.array([
+ self.a * p[1],
+ -self.mu * p[1] - self.b * p[0],
+ 0
+ ]),
+ **self.vector_field_config
+ )
+ new_field.sort(get_norm)
+
+ field.generate_target()
+ for vect in field.target:
+ vect.become(new_field.get_vector(vect.get_start()))
+
+ self.play(*map(
+ FadeOut,
+ [trajs, dots, self.possibility_words]
+ ))
+ self.play(MoveToTarget(field))
+ self.vector_field = new_field
+
+ total_time = 30
+ new_trajs = VGroup(*[
+ self.get_trajectory(
+ sp, total_time,
+ added_steps=10,
+ )
+ for sp in self.start_points
+ ])
+ new_trajs.set_color_by_gradient(BLUE, WHITE)
+ dots.trajs = new_trajs
+
+ self.add(new_trajs, dots)
+ self.play(
+ ShowCreation(
+ new_trajs,
+ lag_ratio=0,
+ run_time=10,
+ rate_func=linear,
+ ),
+ )
+ self.wait()
+
+
class TakeManyTinySteps(IntroduceVectorField):
CONFIG = {
"initial_theta": 60 * DEGREES,
"initial_theta_dot": 0,
+ "initial_theta_tex": "\\pi / 3",
+ "initial_theta_dot_tex": "0",
}
def construct(self):
@@ -1391,10 +1642,10 @@ class TakeManyTinySteps(IntroduceVectorField):
self.add(self.plane, field)
def take_many_time_steps(self):
- delta_t_tracker = ValueTracker(0.5)
+ self.setup_trackers()
+ delta_t_tracker = self.delta_t_tracker
get_delta_t = delta_t_tracker.get_value
-
- time_tracker = ValueTracker(10)
+ time_tracker = self.time_tracker
get_t = time_tracker.get_value
traj = always_redraw(
@@ -1414,40 +1665,9 @@ class TakeManyTinySteps(IntroduceVectorField):
)
)
- t_label, dt_label = labels = VGroup(*[
- VGroup(
- TexMobject("{} = ".format(s)),
- DecimalNumber(0)
- ).arrange(RIGHT, aligned_edge=DOWN)
- for s in ("t", "{\\Delta t}")
- ])
- init_labels = VGroup(
- TexMobject(
- "\\theta_0", "= \\pi / 3",
- tex_to_color_map={"\\theta": BLUE},
- ),
- TexMobject(
- "{\\dot\\theta}_0 = 0",
- tex_to_color_map={"{\\dot\\theta}": YELLOW},
- ),
- )
- for group in labels, init_labels:
- for label in group:
- label.scale(1.25)
- label.add_background_rectangle()
- group.arrange(DOWN)
- group.shift(FRAME_WIDTH * RIGHT / 4)
- labels.to_edge(UP)
- init_labels.shift(2 * DOWN)
-
- dt_label[-1].add_updater(
- lambda d: d.set_value(get_delta_t())
- )
- t_label[-1].add_updater(
- lambda d: d.set_value(
- int(get_t() / get_delta_t()) * get_delta_t()
- )
- )
+ # Labels
+ labels, init_labels = self.get_labels(get_t, get_delta_t)
+ t_label, dt_label = labels
theta_t_label = TexMobject("\\theta(t)...\\text{ish}")
theta_t_label.scale(0.75)
@@ -1485,14 +1705,18 @@ class TakeManyTinySteps(IntroduceVectorField):
count = Integer()
count.scale(1.5)
count.to_edge(LEFT)
- count.shift(UP)
+ count.shift(UP + MED_SMALL_BUFF * UR)
count.add_updater(lambda c: c.set_value(
count_tracker.get_value()
))
count_label = TextMobject("steps")
count_label.scale(1.5)
count_label.add_updater(
- lambda m: m.next_to(count, RIGHT).shift(SMALL_BUFF * DOWN)
+ lambda m: m.next_to(
+ count[-1], RIGHT,
+ submobject_to_align=m[0][0],
+ aligned_edge=DOWN
+ )
)
scaled_vectors = vectors.copy()
@@ -1515,16 +1739,6 @@ class TakeManyTinySteps(IntroduceVectorField):
self.add(count, count_label, scaled_vectors)
self.play(
- # LaggedStartMap(
- # ApplyFunction, vectors,
- # lambda vector: (
- # lambda v: v.scale(
- # 1 / v.get_length()
- # ),
- # vector
- # ),
- # rate_func=there_and_back,
- # ),
ApplyMethod(
count_tracker.set_value,
int(target_time / target_delta_t),
@@ -1535,6 +1749,49 @@ class TakeManyTinySteps(IntroduceVectorField):
self.play(FadeOut(scaled_vectors))
self.wait()
+ def setup_trackers(self):
+ self.delta_t_tracker = ValueTracker(0.5)
+ self.time_tracker = ValueTracker(10)
+
+ def get_labels(self, get_t, get_delta_t):
+ t_label, dt_label = labels = VGroup(*[
+ VGroup(
+ TexMobject("{} = ".format(s)),
+ DecimalNumber(0)
+ ).arrange(RIGHT, aligned_edge=DOWN)
+ for s in ("t", "{\\Delta t}")
+ ])
+
+ dt_label[-1].add_updater(
+ lambda d: d.set_value(get_delta_t())
+ )
+ t_label[-1].add_updater(
+ lambda d: d.set_value(
+ int(np.ceil(get_t() / get_delta_t())) * get_delta_t()
+ )
+ )
+
+ init_labels = VGroup(
+ TexMobject(
+ "\\theta_0", "=", self.initial_theta_tex,
+ tex_to_color_map={"\\theta": BLUE},
+ ),
+ TexMobject(
+ "{\\dot\\theta}_0 =", self.initial_theta_dot_tex,
+ tex_to_color_map={"{\\dot\\theta}": YELLOW},
+ ),
+ )
+ for group in labels, init_labels:
+ for label in group:
+ label.scale(1.25)
+ label.add_background_rectangle()
+ group.arrange(DOWN)
+ group.shift(FRAME_WIDTH * RIGHT / 4)
+ labels.to_edge(UP)
+ init_labels.shift(2 * DOWN)
+
+ return labels, init_labels
+
#
def get_time_step_points(self, delta_t, total_time, theta_0, theta_dot_0):
plane = self.plane
@@ -1580,6 +1837,130 @@ class TakeManyTinySteps(IntroduceVectorField):
return result
+class SetupToTakingManyTinySteps(TakeManyTinySteps):
+ CONFIG = {
+ }
+
+ def construct(self):
+ self.initialize_plane_and_field()
+ self.show_step()
+
+ def show_step(self):
+ self.setup_trackers()
+ get_delta_t = self.delta_t_tracker.get_value
+ get_t = self.time_tracker.get_value
+
+ labels, init_labels = self.get_labels(get_t, get_delta_t)
+ t_label, dt_label = labels
+
+ dt_part = dt_label[1][0][:-1].copy()
+
+ init_labels_rect = SurroundingRectangle(init_labels)
+ init_labels_rect.set_color(PINK)
+
+ field = self.vector_field
+ point = self.plane.coords_to_point(
+ self.initial_theta,
+ self.initial_theta_dot,
+ )
+ dot = Dot(point, color=init_labels_rect.get_color())
+
+ vector_value = field.func(point)
+ vector = field.get_vector(point)
+ vector.scale(
+ get_norm(vector_value) / vector.get_length(),
+ about_point=vector.get_start()
+ )
+ scaled_vector = vector.copy()
+ scaled_vector.scale(
+ get_delta_t(),
+ about_point=scaled_vector.get_start()
+ )
+
+ v_label = TexMobject("\\vec{\\textbf{v}}")
+ v_label.set_stroke(BLACK, 5, background=True)
+ v_label.next_to(vector, LEFT, SMALL_BUFF)
+
+ real_field = field.copy()
+ for v in real_field:
+ p = v.get_start()
+ v.scale(
+ get_norm(field.func(p)) / v.get_length(),
+ about_point=p
+ )
+
+ self.add(init_labels)
+ self.play(ShowCreation(init_labels_rect))
+ self.play(ReplacementTransform(
+ init_labels_rect,
+ dot,
+ ))
+ self.wait()
+ self.add(vector, dot)
+ self.play(
+ ShowCreation(vector),
+ FadeInFrom(v_label, RIGHT),
+ )
+ self.play(FadeInFromDown(dt_label))
+ self.wait()
+
+ #
+ v_label.generate_target()
+ dt_part.generate_target()
+ dt_part.target.next_to(scaled_vector, LEFT, SMALL_BUFF)
+ v_label.target.next_to(dt_part.target, LEFT, SMALL_BUFF)
+ rect = BackgroundRectangle(
+ VGroup(v_label.target, dt_part.target)
+ )
+
+ self.add(rect, v_label, dt_part)
+ self.play(
+ ReplacementTransform(vector, scaled_vector),
+ FadeIn(rect),
+ MoveToTarget(v_label),
+ MoveToTarget(dt_part),
+ )
+ self.add(scaled_vector, dot)
+ self.wait()
+
+ self.play(
+ LaggedStart(*[
+ Transform(
+ sm1, sm2,
+ rate_func=there_and_back_with_pause,
+ )
+ for sm1, sm2 in zip(field, real_field)
+ ], lag_ratio=0.001, run_time=3)
+ )
+ self.wait()
+
+
+class ShowClutterPrevention(SetupToTakingManyTinySteps):
+ def construct(self):
+ self.initialize_plane_and_field()
+
+ # Copied from above scene
+ field = self.vector_field
+ real_field = field.copy()
+ for v in real_field:
+ p = v.get_start()
+ v.scale(
+ get_norm(field.func(p)) / v.get_length(),
+ about_point=p
+ )
+
+ self.play(
+ LaggedStart(*[
+ Transform(
+ sm1, sm2,
+ rate_func=there_and_back_with_pause,
+ )
+ for sm1, sm2 in zip(field, real_field)
+ ], lag_ratio=0.001, run_time=3)
+ )
+ self.wait()
+
+
class ManyStepsFromDifferentStartingPoints(TakeManyTinySteps):
CONFIG = {
"initial_thetas": np.linspace(0.1, PI - 0.1, 10),
diff --git a/active_projects/ode/part1/shared_constructs.py b/active_projects/ode/part1/shared_constructs.py
index 0bed33144..37aa12a00 100644
--- a/active_projects/ode/part1/shared_constructs.py
+++ b/active_projects/ode/part1/shared_constructs.py
@@ -64,3 +64,55 @@ def get_vector_symbol(*texs, **kwargs):
config.update(kwargs)
array = [[tex] for tex in texs]
return Matrix(array, **config)
+
+
+def get_heart_var(index):
+ heart = SuitSymbol("hearts")
+ if index == 1:
+ heart.set_color(BLUE_C)
+ elif index == 2:
+ heart.set_color(GREEN)
+ heart.set_height(0.7)
+ index = Integer(index)
+ index.move_to(heart.get_corner(DR))
+ heart.add(index)
+ return heart
+
+
+def get_heart_var_deriv(index):
+ heart = get_heart_var(index)
+ filler_tex = "T"
+ deriv = TexMobject("{d", filler_tex, "\\over", "dt}")
+ deriv.scale(2)
+ filler = deriv.get_part_by_tex(filler_tex)
+ heart.match_height(filler)
+ heart.move_to(filler)
+ heart.scale(1.5, about_edge=UL)
+ deriv.remove(filler)
+ deriv.add(heart)
+ deriv.heart = heart
+ return deriv
+
+
+def get_love_equation1():
+ equation = VGroup(
+ get_heart_var_deriv(1),
+ TexMobject("=").scale(2),
+ TexMobject("a").scale(2),
+ get_heart_var(2)
+ )
+ equation.arrange(RIGHT)
+ equation[-1].shift(SMALL_BUFF * DL)
+ return equation
+
+
+def get_love_equation2():
+ equation = VGroup(
+ get_heart_var_deriv(2),
+ TexMobject("=").scale(2),
+ TexMobject("-b").scale(2),
+ get_heart_var(1),
+ )
+ equation.arrange(RIGHT)
+ equation[-1].shift(SMALL_BUFF * DL)
+ return equation
diff --git a/active_projects/ode/part1/staging.py b/active_projects/ode/part1/staging.py
index f2c48ca0a..8fcb852ae 100644
--- a/active_projects/ode/part1/staging.py
+++ b/active_projects/ode/part1/staging.py
@@ -47,15 +47,28 @@ class VectorFieldTest(Scene):
class ShowRect(Scene):
+ CONFIG = {
+ "height": 1,
+ "width": 3,
+ }
+
def construct(self):
- rect = Rectangle()
+ rect = Rectangle(
+ height=self.height,
+ width=self.width,
+ )
rect.set_stroke(YELLOW)
- rect.set_height(1)
- rect.set_width(3, stretch=True)
self.play(ShowCreation(rect))
self.play(FadeOut(rect))
+class ShowSquare(ShowRect):
+ CONFIG = {
+ "height": 3,
+ "width": 3,
+ }
+
+
class PeriodFormula(Scene):
def construct(self):
formula = get_period_formula()
@@ -259,6 +272,11 @@ class RabbitFoxEquation(PhaseSpaceOfPopulationModel):
class ShowGravityAcceleration(Scene):
+ CONFIG = {
+ "flash": True,
+ "add_ball_copies": True,
+ }
+
def construct(self):
self.add_gravity_field()
self.add_title()
@@ -332,24 +350,10 @@ class ShowGravityAcceleration(Scene):
)
def show_trajectory(self):
- ball = Circle(
- stroke_width=1,
- stroke_color=WHITE,
- fill_color=GREY,
- fill_opacity=1,
- sheen_factor=1,
- sheen_direction=UL,
- radius=0.25,
- )
- randy = Randolph(mode="pondering")
- randy.eyes.set_stroke(BLACK, 0.5)
- randy.match_height(ball)
- randy.scale(0.75)
- randy.move_to(ball)
- ball.add(randy)
-
total_time = 6
+ ball = self.get_ball()
+
p0 = 3 * DOWN + 5 * LEFT
v0 = 2.8 * UP + 1.5 * RIGHT
g = 0.9 * DOWN
@@ -416,11 +420,13 @@ class ShowGravityAcceleration(Scene):
for t1, t2 in zip(times, times[1:]):
v_vect_copy = v_vect.copy()
v_vect_copies.add(v_vect_copy)
- self.add(v_vect_copy)
ball_copy = ball.copy()
ball_copy.clear_updaters()
ball_copies.add(ball_copy)
- self.add(ball_copy)
+
+ if self.add_ball_copies:
+ self.add(v_vect_copy)
+ self.add(ball_copy, ball)
dashed_graph.save_state()
kw = {
@@ -430,7 +436,7 @@ class ShowGravityAcceleration(Scene):
alpha
)
}
- self.play(
+ anims = [
ShowCreation(dashed_graph, **kw),
MoveAlongPath(ball, graph, **kw),
MoveAlongPath(v_point, velocity_graph, **kw),
@@ -438,9 +444,10 @@ class ShowGravityAcceleration(Scene):
time_tracker.increment_value, 1,
rate_func=linear
),
- flash,
- run_time=1,
- )
+ ]
+ if self.flash:
+ anims.append(flash)
+ self.play(*anims, run_time=1)
dashed_graph.restore()
randy.clear_updaters()
self.play(FadeOut(time_group))
@@ -505,6 +512,517 @@ class ShowGravityAcceleration(Scene):
)
self.wait()
+ #
+ def get_ball(self):
+ ball = Circle(
+ stroke_width=1,
+ stroke_color=WHITE,
+ fill_color=GREY,
+ fill_opacity=1,
+ sheen_factor=1,
+ sheen_direction=UL,
+ radius=0.25,
+ )
+ randy = Randolph(mode="pondering")
+ randy.eyes.set_stroke(BLACK, 0.5)
+ randy.match_height(ball)
+ randy.scale(0.75)
+ randy.move_to(ball)
+ ball.add(randy)
+ return ball
+
+
+class ShowSimpleTrajectory(ShowGravityAcceleration):
+ CONFIG = {
+ "flash": False,
+ }
+
+ def construct(self):
+ self.show_trajectory()
+
+
+class SimpleProjectileEquation(ShowGravityAcceleration):
+ CONFIG = {
+ "y0": 0,
+ "g": 9.8,
+ "axes_config": {
+ "x_min": 0,
+ "x_max": 6,
+ "x_axis_config": {
+ "unit_size": 1.5,
+ "tip_width": 0.15,
+ },
+ "y_min": -30,
+ "y_max": 35,
+ "y_axis_config": {
+ "unit_size": 0.1,
+ "numbers_with_elongated_ticks": range(
+ -30, 35, 10
+ ),
+ "tick_size": 0.05,
+ "numbers_to_show": range(-30, 31, 10),
+ "tip_width": 0.15,
+ },
+ "center_point": 2 * LEFT,
+ }
+ }
+
+ def construct(self):
+ self.add_axes()
+ self.setup_trajectory()
+
+ self.show_trajectory()
+ self.show_equation()
+ self.solve_for_velocity()
+ self.solve_for_position()
+
+ def add_axes(self):
+ axes = self.axes = Axes(**self.axes_config)
+ axes.set_stroke(width=2)
+ axes.add_coordinates()
+
+ t_label = TexMobject("t")
+ t_label.next_to(axes.x_axis.get_right(), UL)
+ axes.add(t_label)
+
+ self.add(axes)
+
+ def setup_trajectory(self):
+ axes = self.axes
+ total_time = self.total_time = 5
+
+ ball = self.get_ball()
+ offset_vector = 3 * LEFT
+
+ g = self.g
+ y0 = self.y0
+ v0 = 0.5 * g * total_time
+
+ t_tracker = ValueTracker(0)
+ get_t = t_tracker.get_value
+
+ # Position
+ def y_func(t):
+ return -0.5 * g * t**2 + v0 * t + y0
+
+ graph_template = axes.get_graph(y_func, x_max=total_time)
+ graph_template.set_stroke(width=2)
+ traj_template = graph_template.copy()
+ traj_template.stretch(0, 0)
+ traj_template.move_to(
+ axes.coords_to_point(0, 0), DOWN
+ )
+ traj_template.shift(offset_vector)
+ traj_template.set_stroke(width=0.5)
+
+ graph = VMobject()
+ graph.set_stroke(BLUE, 2)
+ traj = VMobject()
+ traj.set_stroke(WHITE, 0.5)
+ graph.add_updater(lambda g: g.pointwise_become_partial(
+ graph_template, 0, get_t() / total_time
+ ))
+ traj.add_updater(lambda t: t.pointwise_become_partial(
+ traj_template, 0, get_t() / total_time
+ ))
+
+ def get_ball_point():
+ return axes.coords_to_point(
+ 0, y_func(get_t())
+ ) + offset_vector
+
+ f_always(ball.move_to, get_ball_point)
+
+ h_line = always_redraw(lambda: DashedLine(
+ get_ball_point(),
+ axes.input_to_graph_point(get_t(), graph_template),
+ stroke_width=1,
+ ))
+
+ y_label = TexMobject("y", "(t)")
+ y_label.set_color_by_tex("y", BLUE)
+ y_label.add_updater(
+ lambda m: m.next_to(
+ graph.get_last_point(),
+ UR, SMALL_BUFF,
+ )
+ )
+
+ # Velocity
+ def v_func(t):
+ return -g * t + v0
+
+ def get_v_vect():
+ return Vector(
+ axes.y_axis.unit_size * v_func(get_t()) * UP,
+ color=RED,
+ )
+ v_vect = always_redraw(
+ lambda: get_v_vect().shift(get_ball_point())
+ )
+ v_brace = always_redraw(lambda: Brace(v_vect, LEFT))
+ dy_dt_label = TexMobject(
+ "{d", "y", "\\over dt}", "(t)",
+ )
+ dy_dt_label.scale(0.8)
+ dy_dt_label.set_color_by_tex("y", BLUE)
+ y_dot_label = TexMobject("\\dot y", "(t)")
+ y_dot_label.set_color_by_tex("\\dot y", RED)
+ for label in dy_dt_label, y_dot_label:
+ label.add_updater(lambda m: m.next_to(
+ v_brace, LEFT, SMALL_BUFF,
+ ))
+
+ graphed_v_vect = always_redraw(
+ lambda: get_v_vect().shift(
+ axes.coords_to_point(get_t(), 0)
+ )
+ )
+ v_graph_template = axes.get_graph(
+ v_func, x_max=total_time,
+ )
+ v_graph = VMobject()
+ v_graph.set_stroke(RED, 2)
+ v_graph.add_updater(lambda m: m.pointwise_become_partial(
+ v_graph_template,
+ 0, get_t() / total_time,
+ ))
+
+ # Acceleration
+ def get_a_vect():
+ return Vector(
+ axes.y_axis.unit_size * g * DOWN
+ )
+
+ a_vect = get_a_vect()
+ a_vect.add_updater(lambda a: a.move_to(
+ get_ball_point(), UP,
+ ))
+ a_brace = Brace(a_vect, RIGHT)
+ always(a_brace.next_to, a_vect, RIGHT, SMALL_BUFF)
+ d2y_dt2_label = TexMobject(
+ "d^2", "{y}", "\\over dt}", "(t)"
+ )
+ d2y_dt2_label.scale(0.8)
+ d2y_dt2_label.set_color_by_tex(
+ "y", BLUE,
+ )
+ y_ddot_label = TexMobject("\\ddot y", "(t)")
+ y_ddot_label.set_color_by_tex("\\ddot y", YELLOW)
+ for label in d2y_dt2_label, y_ddot_label:
+ label.add_updater(lambda m: m.next_to(
+ a_brace, RIGHT, SMALL_BUFF
+ ))
+ a_graph = axes.get_graph(
+ lambda t: -g, x_max=total_time,
+ )
+ a_graph.set_stroke(YELLOW, 2)
+
+ graphed_a_vect = get_a_vect()
+ graphed_a_vect.add_updater(lambda a: a.move_to(
+ axes.coords_to_point(get_t(), 0), UP,
+ ))
+
+ self.set_variables_as_attrs(
+ t_tracker,
+ graph,
+ y_label,
+ traj,
+ h_line,
+ v_vect,
+ v_brace,
+ dy_dt_label,
+ y_dot_label,
+ ball,
+ graphed_v_vect,
+ v_graph,
+ a_vect,
+ a_brace,
+ d2y_dt2_label,
+ y_ddot_label,
+ a_graph,
+ graphed_a_vect,
+ )
+
+ def show_trajectory(self):
+ self.add(
+ self.h_line,
+ self.traj,
+ self.ball,
+ self.graph,
+ self.y_label,
+ )
+ self.play_trajectory()
+ self.wait()
+
+ self.add(
+ self.v_vect,
+ self.v_brace,
+ self.dy_dt_label,
+ self.ball,
+ self.graphed_v_vect,
+ self.v_graph,
+ )
+ self.play_trajectory()
+ self.wait()
+
+ self.add(
+ self.a_vect,
+ self.ball,
+ self.a_brace,
+ self.d2y_dt2_label,
+ self.a_graph,
+ self.graphed_a_vect,
+ )
+ self.play_trajectory()
+ self.wait()
+
+ self.play(
+ ReplacementTransform(
+ self.dy_dt_label,
+ self.y_dot_label,
+ ),
+ ShowCreationThenFadeAround(
+ self.y_dot_label,
+ ),
+ )
+ self.play(
+ ReplacementTransform(
+ self.d2y_dt2_label,
+ self.y_ddot_label,
+ ),
+ ShowCreationThenFadeAround(
+ self.y_ddot_label,
+ ),
+ )
+
+ def show_equation(self):
+ y_ddot = self.y_ddot_label
+ new_y_ddot = y_ddot.deepcopy()
+ new_y_ddot.clear_updaters()
+
+ equation = VGroup(
+ new_y_ddot,
+ *TexMobject(
+ "=", "-g",
+ tex_to_color_map={"-g": YELLOW},
+ ),
+ )
+ new_y_ddot.next_to(equation[1], LEFT, SMALL_BUFF)
+ equation.move_to(self.axes)
+ equation.to_edge(UP)
+
+ self.play(
+ TransformFromCopy(y_ddot, new_y_ddot),
+ Write(equation[1:]),
+ FadeOut(self.graph),
+ FadeOut(self.y_label),
+ FadeOut(self.h_line),
+ FadeOut(self.v_graph),
+ FadeOut(self.graphed_v_vect),
+ FadeOut(self.graphed_a_vect),
+ )
+
+ self.equation = equation
+
+ def solve_for_velocity(self):
+ axes = self.axes
+ equation = self.equation
+ v_graph = self.v_graph.deepcopy()
+ v_graph.clear_updaters()
+ v_start_point = v_graph.get_start()
+ origin = axes.coords_to_point(0, 0)
+ offset = v_start_point - origin
+ v_graph.shift(-offset)
+
+ tex_question, answer1, answer2 = derivs = [
+ TexMobject(
+ "{d", "(", *term, ")", "\\over", "dt}", "(t)",
+ "=", "-g",
+ tex_to_color_map={
+ "-g": YELLOW,
+ "v_0": RED,
+ "?": RED,
+ }
+ )
+ for term in [
+ ("?", "?", "?", "?"),
+ ("-g", "t"),
+ ("-g", "t", "+", "v_0",),
+ ]
+ ]
+ for x in range(2):
+ answer1.submobjects.insert(
+ 4, VectorizedPoint(answer1[4].get_left())
+ )
+ for deriv in derivs:
+ deriv.next_to(equation, DOWN, MED_LARGE_BUFF)
+
+ question = TextMobject(
+ "What function has slope $-g$?",
+ tex_to_color_map={"$-g$": YELLOW},
+ )
+ question.next_to(tex_question, DOWN)
+ question.set_stroke(BLACK, 5, background=True)
+ question.add_background_rectangle()
+
+ v0_dot = Dot(v_start_point, color=PINK)
+ v0_label = TexMobject("v_0")
+ v0_label.set_color(RED)
+ v0_label.next_to(v0_dot, UR, buff=0)
+
+ y_dot_equation = TexMobject(
+ "{\\dot y}", "(t)", "=",
+ "-g", "t", "+", "v_0",
+ tex_to_color_map={
+ "{\\dot y}": RED,
+ "-g": YELLOW,
+ "v_0": RED,
+ }
+ )
+ y_dot_equation.to_corner(UR)
+
+ self.play(
+ FadeInFrom(tex_question, DOWN),
+ FadeInFrom(question, UP)
+ )
+ self.wait()
+ self.add(v_graph, question)
+ self.play(
+ ReplacementTransform(tex_question, answer1),
+ ShowCreation(v_graph),
+ )
+ self.wait()
+ self.play(
+ ReplacementTransform(answer1, answer2),
+ v_graph.shift, offset,
+ )
+ self.play(
+ FadeInFromLarge(v0_dot),
+ FadeInFromDown(v0_label),
+ )
+ self.wait()
+ self.play(
+ TransformFromCopy(
+ answer2[2:6], y_dot_equation[3:],
+ ),
+ Write(y_dot_equation[:3]),
+ equation.shift, LEFT,
+ )
+ self.play(
+ FadeOut(question),
+ FadeOut(answer2),
+ )
+
+ self.remove(v_graph)
+ self.add(self.v_graph)
+ self.y_dot_equation = y_dot_equation
+
+ def solve_for_position(self):
+ # Largely copied from above...not great
+ equation = self.equation
+ y_dot_equation = self.y_dot_equation
+ graph = self.graph
+
+ all_terms = [
+ ("?", "?", "?", "?"),
+ ("-", "(1/2)", "g", "t^2", "+", "v_0", "t"),
+ ("-", "(1/2)", "g", "t^2", "+", "v_0", "t", "+", "y_0"),
+ ]
+ tex_question, answer1, answer2 = derivs = [
+ TexMobject(
+ "{d", "(", *term, ")", "\\over", "dt}", "(t)",
+ "=",
+ "-g", "t", "+", "v_0",
+ tex_to_color_map={
+ "g": YELLOW,
+ "v_0": RED,
+ "?": BLUE,
+ "y_0": BLUE,
+ }
+ )
+ for term in all_terms
+ ]
+ answer1.scale(0.8)
+ answer2.scale(0.8)
+ for deriv, terms in zip(derivs, all_terms):
+ for x in range(len(all_terms[-1]) - len(terms)):
+ n = 2 + len(terms)
+ deriv.submobjects.insert(
+ n, VectorizedPoint(deriv[n].get_left())
+ )
+ deriv.next_to(
+ VGroup(equation, y_dot_equation),
+ DOWN, MED_LARGE_BUFF + SMALL_BUFF
+ )
+ deriv.shift_onto_screen()
+ deriv.add_background_rectangle_to_submobjects()
+
+ y_equation = TexMobject(
+ "y", "(t)", "=",
+ "-", "(1/2)", "g", "t^2",
+ "+", "v_0", "t",
+ "+", "y_0",
+ tex_to_color_map={
+ "y": BLUE,
+ "g": YELLOW,
+ "v_0": RED,
+ }
+ )
+ y_equation.next_to(
+ VGroup(equation, y_dot_equation),
+ DOWN, MED_LARGE_BUFF,
+ )
+
+ self.play(
+ FadeInFrom(tex_question, DOWN),
+ )
+ self.wait()
+ self.add(graph, tex_question)
+ self.play(
+ ReplacementTransform(tex_question, answer1),
+ ShowCreation(graph),
+ )
+ self.add(graph, answer1)
+ self.wait()
+ self.play(ReplacementTransform(answer1, answer2))
+ self.add(graph, answer2)
+ g_updaters = graph.updaters
+ graph.clear_updaters()
+ self.play(
+ graph.shift, 2 * DOWN,
+ rate_func=there_and_back,
+ run_time=2,
+ )
+ graph.add_updater(g_updaters[0])
+ self.wait()
+ br = BackgroundRectangle(y_equation)
+ self.play(
+ FadeIn(br),
+ ReplacementTransform(
+ answer2[2:11],
+ y_equation[3:]
+ ),
+ FadeIn(y_equation[:3]),
+ FadeOut(answer2[:2]),
+ FadeOut(answer2[11:]),
+ )
+ self.play(ShowCreationThenFadeAround(y_equation))
+ self.play_trajectory()
+
+ #
+ def play_trajectory(self, *added_anims, **kwargs):
+ self.t_tracker.set_value(0)
+ self.play(
+ ApplyMethod(
+ self.t_tracker.set_value, 5,
+ rate_func=linear,
+ run_time=self.total_time,
+ ),
+ *added_anims,
+ )
+ self.wait()
+
class ShowDerivativeVideo(Scene):
def construct(self):
@@ -1736,8 +2254,476 @@ class TwoBodiesWithZPart(TwoBodiesInSpace):
body.velocity += (6 / 60) * OUT
-class DefineODECopy(DefineODE):
- pass
+class LoveExample(PiCreatureScene):
+ def construct(self):
+ self.show_hearts()
+ self.add_love_trackers()
+ self.break_down_your_rule()
+ self.break_down_their_rule()
+
+ def create_pi_creatures(self):
+ you = You()
+ you.shift(FRAME_WIDTH * LEFT / 4)
+ you.to_edge(DOWN)
+
+ tau = TauCreature(color=GREEN)
+ tau.flip()
+ tau.shift(FRAME_WIDTH * RIGHT / 4)
+ tau.to_edge(DOWN)
+
+ self.you = you
+ self.tau = tau
+ return (you, tau)
+
+ def show_hearts(self):
+ you, tau = self.you, self.tau
+ hearts = VGroup()
+ n_hearts = 20
+ for x in range(n_hearts):
+ heart = SuitSymbol("hearts")
+ heart.scale(0.5 + 2 * np.random.random())
+ heart.shift(np.random.random() * 4 * RIGHT)
+ heart.shift(np.random.random() * 4 * UP)
+ hearts.add(heart)
+ hearts.move_to(2 * DOWN)
+ hearts.add_updater(lambda m, dt: m.shift(2 * dt * UP))
+
+ self.add(hearts)
+ self.play(
+ LaggedStartMap(
+ UpdateFromAlphaFunc, hearts,
+ lambda heart: (
+ heart,
+ lambda h, a: h.set_opacity(
+ there_and_back(a)
+ ).shift(0.02 * UP)
+ ),
+ lag_ratio=0.01,
+ run_time=3,
+ suspend_mobject_updating=False,
+ ),
+ ApplyMethod(
+ you.change, 'hooray', tau.eyes,
+ run_time=2,
+ rate_func=squish_rate_func(smooth, 0.5, 1)
+ ),
+ ApplyMethod(
+ tau.change, 'hooray', you.eyes,
+ run_time=2,
+ rate_func=squish_rate_func(smooth, 0.5, 1)
+ ),
+ )
+ self.remove(hearts)
+ self.wait()
+
+ def add_love_trackers(self):
+ self.init_ps_point()
+ self.add_love_decimals()
+ self.add_love_number_lines()
+ self.tie_creature_state_to_ps_point()
+
+ self.play(Rotating(
+ self.ps_point,
+ radians=-7 * TAU / 8,
+ about_point=ORIGIN,
+ run_time=10,
+ rate_func=linear,
+ ))
+ self.wait()
+
+ def break_down_your_rule(self):
+ label1 = self.love_1_label
+ label2 = self.love_2_label
+ ps_point = self.ps_point
+
+ up_arrow = Vector(UP, color=GREEN)
+ down_arrow = Vector(DOWN, color=RED)
+ for arrow in (up_arrow, down_arrow):
+ arrow.next_to(label1, RIGHT)
+
+ self.play(GrowArrow(up_arrow))
+ self.play(
+ self.tau.love_eyes.scale, 1.25,
+ self.tau.love_eyes.set_color, BLUE_C,
+ rate_func=there_and_back,
+ )
+ self.play(
+ ps_point.shift, 6 * RIGHT,
+ run_time=2,
+ )
+ self.wait()
+ ps_point.shift(13 * DOWN)
+ self.play(
+ FadeOut(up_arrow),
+ GrowArrow(down_arrow),
+ )
+ self.play(
+ ps_point.shift, 11 * LEFT,
+ run_time=3,
+ )
+ self.wait()
+
+ # Derivative
+ equation = get_love_equation1()
+ equation.shift(0.5 * UP)
+ deriv, equals, a, h2 = equation
+
+ self.play(
+ Write(deriv[:-1]),
+ Write(equals),
+ Write(a),
+ TransformFromCopy(label1[0], deriv.heart),
+ TransformFromCopy(label2[0], h2),
+ )
+ self.wait()
+ self.play(
+ equation.scale, 0.5,
+ equation.to_corner, UL,
+ FadeOut(down_arrow)
+ )
+
+ def break_down_their_rule(self):
+ label1 = self.love_1_label
+ label2 = self.love_2_label
+ ps_point = self.ps_point
+
+ up_arrow = Vector(UP, color=GREEN)
+ down_arrow = Vector(DOWN, color=RED)
+ for arrow in (up_arrow, down_arrow):
+ arrow.next_to(label2, RIGHT)
+
+ # Derivative
+ equation = get_love_equation2()
+ equation.shift(0.5 * UP)
+ deriv, equals, mb, h1 = equation
+
+ self.play(
+ Write(deriv[:-1]),
+ Write(equals),
+ Write(mb),
+ TransformFromCopy(label1[0], h1),
+ TransformFromCopy(label2[0], deriv.heart),
+ )
+
+ self.play(GrowArrow(up_arrow))
+ self.play(
+ ps_point.shift, 13 * UP,
+ run_time=3,
+ )
+ self.wait()
+ self.play(
+ ps_point.shift, 11 * RIGHT,
+ )
+ self.play(
+ FadeOut(up_arrow),
+ GrowArrow(down_arrow),
+ )
+ self.play(
+ ps_point.shift, 13 * DOWN,
+ run_time=3,
+ )
+ self.wait()
+
+ #
+ def init_ps_point(self):
+ self.ps_point = VectorizedPoint(np.array([5.0, 5.0, 0]))
+
+ def get_love1(self):
+ return self.ps_point.get_location()[0]
+
+ def get_love2(self):
+ return self.ps_point.get_location()[1]
+
+ def set_loves(self, love1=None, love2=None):
+ if love1 is not None:
+ self.ps_point.set_x(love1)
+ if love2 is not None:
+ self.ps_point.set_x(love2)
+
+ def add_love_decimals(self):
+ self.love_1_label = self.add_love_decimal(
+ 1, self.get_love1, self.you.get_color(), -3,
+ )
+ self.love_2_label = self.add_love_decimal(
+ 2, self.get_love2, self.tau.get_color(), 3,
+ )
+
+ def add_love_decimal(self, index, value_func, color, x_coord):
+ d = DecimalNumber(include_sign=True)
+ d.add_updater(lambda d: d.set_value(value_func()))
+
+ label = get_heart_var(index)
+ label.move_to(x_coord * RIGHT)
+ label.to_edge(UP)
+ eq = TexMobject("=")
+ eq.next_to(label, RIGHT, SMALL_BUFF)
+ eq.shift(SMALL_BUFF * UP)
+ d.next_to(eq, RIGHT, SMALL_BUFF)
+
+ self.add(label, eq, d)
+ return VGroup(label, eq, d)
+
+ def add_love_number_lines(self):
+ nl1 = NumberLine(
+ x_min=-8,
+ x_max=8,
+ unit_size=0.25,
+ tick_frequency=2,
+ number_scale_val=0.25,
+ )
+ nl1.set_stroke(width=1)
+ nl1.next_to(self.love_1_label, DOWN)
+ nl1.add_numbers(*range(-6, 8, 2))
+
+ nl2 = nl1.copy()
+ nl2.next_to(self.love_2_label, DOWN)
+
+ dot1 = Dot(color=self.you.get_color())
+ dot1.add_updater(lambda d: d.move_to(
+ nl1.number_to_point(self.get_love1())
+ ))
+ dot2 = Dot(color=self.tau.get_color())
+ dot2.add_updater(lambda d: d.move_to(
+ nl2.number_to_point(self.get_love2())
+ ))
+
+ self.add(nl1, nl2, dot1, dot2)
+
+ def get_love_eyes(self, eyes):
+ hearts = VGroup()
+ for eye in eyes:
+ heart = SuitSymbol("hearts")
+ heart.match_width(eye)
+ heart.move_to(eye)
+ heart.scale(1.25)
+ heart.set_stroke(BLACK, 1)
+ hearts.add(heart)
+ hearts.add_updater(
+ lambda m: m.move_to(eyes)
+ )
+ return hearts
+
+ def tie_creature_state_to_ps_point(self):
+ # Quite a mess, but I'm coding in a rush here...
+ you = self.you
+ you_copy = you.copy()
+ tau = self.tau
+ tau_copy = tau.copy()
+
+ you.love_eyes = self.get_love_eyes(you.eyes)
+ tau.love_eyes = self.get_love_eyes(tau.eyes)
+
+ self.add(you.love_eyes)
+ self.add(tau.love_eyes)
+
+ you_height = you.get_height()
+ tau_height = tau.get_height()
+
+ you_bottom = you.get_bottom()
+ tau_bottom = tau.get_bottom()
+
+ def update_you(y):
+ love = self.get_love1()
+
+ cutoff_values = [
+ -5, -3, -1, 1, 3, 5
+ ]
+ modes = [
+ "angry", "sassy", "hesitant",
+ "plain",
+ "happy", "hooray", "surprised",
+ ]
+
+ if love < cutoff_values[0]:
+ y.change(modes[0])
+ elif love >= cutoff_values[-1]:
+ y.change(modes[-1])
+ else:
+ i = 0
+ while cutoff_values[i] < love:
+ i += 1
+ m1 = modes[i - 1]
+ m2 = modes[i]
+ y.change(m1)
+ you_copy.change(m2)
+ for mob in y, you_copy:
+ mob.set_height(you_height)
+ mob.move_to(you_bottom, DOWN)
+
+ alpha = inverse_interpolate(
+ cutoff_values[i - 1],
+ cutoff_values[i],
+ love,
+ )
+ s_alpha = squish_rate_func(smooth, 0.25, 1)(alpha)
+ if s_alpha > 0:
+ y.align_data(you_copy)
+ f1 = y.family_members_with_points()
+ f2 = you_copy.family_members_with_points()
+ for sm1, sm2 in zip(f1, f2):
+ sm1.interpolate(sm1, sm2, s_alpha)
+ y.look_at(tau.eyes)
+ if love < -4:
+ y.look_at(LEFT_SIDE)
+ # y.move_to(
+ # you_bottom + 0.025 * love * RIGHT, DOWN,
+ # )
+
+ l_alpha = np.clip(
+ inverse_interpolate(5, 5.5, love),
+ 0, 1
+ )
+ y.eyes.set_opacity(1 - l_alpha)
+ y.love_eyes.set_opacity(l_alpha)
+
+ return y
+
+ def update_tau(t):
+ love = self.get_love2()
+
+ cutoff_values = [
+ -5, -1.7, 1.7, 5
+ ]
+ modes = [
+ "angry", "confused", "plain",
+ "hooray", "hooray"
+ ]
+
+ if love < cutoff_values[0]:
+ t.change(modes[0])
+ elif love >= cutoff_values[-1]:
+ t.change(modes[-1])
+ else:
+ i = 0
+ while cutoff_values[i] < love:
+ i += 1
+ m1 = modes[i - 1]
+ m2 = modes[i]
+ t.change(m1)
+ tau_copy.change(m2)
+ for mob in t, tau_copy:
+ mob.set_height(tau_height)
+ mob.move_to(tau_bottom, DOWN)
+
+ alpha = inverse_interpolate(
+ cutoff_values[i - 1],
+ cutoff_values[i],
+ love,
+ )
+ s_alpha = squish_rate_func(smooth, 0.25, 1)(alpha)
+ if s_alpha > 0:
+ t.align_data(tau_copy)
+ f1 = t.family_members_with_points()
+ f2 = tau_copy.family_members_with_points()
+ for sm1, sm2 in zip(f1, f2):
+ sm1.interpolate(sm1, sm2, s_alpha)
+ # t.move_to(
+ # tau_bottom + 0.025 * love * LEFT, DOWN,
+ # )
+ t.look_at(you.eyes)
+ if love < -4:
+ t.look_at(RIGHT_SIDE)
+
+ l_alpha = np.clip(
+ inverse_interpolate(5, 5.5, love),
+ 0, 1
+ )
+ t.eyes.set_opacity(1 - l_alpha)
+ t.love_eyes.set_opacity(l_alpha)
+
+ you.add_updater(update_you)
+ tau.add_updater(update_tau)
+
+ self.pi_creatures = VGroup()
+
+
+class ComparePhysicsToLove(Scene):
+ def construct(self):
+ ode = get_ode()
+ ode.to_edge(UP)
+ thetas = ode.get_parts_by_tex("theta")
+
+ love = VGroup(
+ get_love_equation1(),
+ get_love_equation2(),
+ )
+ love.scale(0.5)
+ love.arrange(DOWN, buff=MED_LARGE_BUFF, aligned_edge=LEFT)
+ love.move_to(DOWN)
+ hearts = VGroup(*filter(
+ lambda sm: isinstance(sm, SuitSymbol),
+ love.get_family()
+ ))
+
+ arrow = DoubleArrow(love.get_top(), ode.get_bottom())
+
+ self.play(FadeInFrom(ode, DOWN))
+ self.play(FadeInFrom(love, UP))
+ self.wait()
+ self.play(LaggedStartMap(
+ ShowCreationThenFadeAround,
+ thetas,
+ ))
+ self.play(LaggedStartMap(
+ ShowCreationThenFadeAround,
+ hearts,
+ ))
+ self.wait()
+ self.play(ShowCreation(arrow))
+ self.wait()
+
+
+class FramesComparingPhysicsToLove(Scene):
+ CONFIG = {
+ "camera_config": {"background_color": DARKER_GREY}
+ }
+
+ def construct(self):
+ ode = get_ode()
+ ode.to_edge(UP)
+
+ love = VGroup(
+ get_love_equation1(),
+ get_love_equation2(),
+ )
+ love.scale(0.5)
+ love.arrange(DOWN, buff=MED_LARGE_BUFF, aligned_edge=LEFT)
+
+ frames = VGroup(*[
+ ScreenRectangle(
+ height=3.5,
+ fill_color=BLACK,
+ fill_opacity=1,
+ stroke_width=0,
+ )
+ for x in range(2)
+ ])
+ frames.arrange(RIGHT, buff=LARGE_BUFF)
+ frames.shift(DOWN)
+
+ animated_frames = AnimatedBoundary(frames)
+
+ ode.next_to(frames[0], UP)
+ love.next_to(frames[1], UP)
+
+ self.add(frames, animated_frames)
+ self.add(ode, love)
+
+ self.wait(15)
+
+
+class PassageOfTime(Scene):
+ def construct(self):
+ clock = Clock()
+ clock[0].set_color(BLUE)
+ clock.set_stroke(width=1)
+ clock.scale(0.8)
+ clock.to_corner(UL)
+ passage = ClockPassesTime(
+ clock,
+ hours_passed=48,
+ )
+ self.play(passage, run_time=10)
class WriteODESolvingCode(ExternallyAnimatedScene):