A community-maintained Python framework for creating mathematical animations.
New scenes for diffyq part3
Grant Sanderson4196bb627e57
diff --git a/active_projects/ode/all_part3_scenes.py b/active_projects/ode/all_part3_scenes.pyindex 97951066b..9024de0c3 100644--- a/active_projects/ode/all_part3_scenes.py+++ b/active_projects/ode/all_part3_scenes.py@@ -2,6 +2,7 @@ from active_projects.ode.part3.staging import *from active_projects.ode.part3.temperature_graphs import *from active_projects.ode.part3.pi_creature_scenes import *from active_projects.ode.part3.wordy_scenes import *+from active_projects.ode.part3.discrete_case import *OUTPUT_DIRECTORY = "ode/part3"@@ -27,7 +28,10 @@ SCENES_IN_ORDER = [BoundaryConditionReference,GiantCross,SimulateRealSineCurve,+ DerivativesOfLinearFunction,+ StraightLine3DGraph,SimulateLinearGraph,+ EmphasizeBoundaryPoints,# SimpleCosExpGraph,# AddMultipleSolutions,diff --git a/active_projects/ode/part2/heat_equation.py b/active_projects/ode/part2/heat_equation.pyindex 4d8294bdd..d2f40595f 100644--- a/active_projects/ode/part2/heat_equation.py+++ b/active_projects/ode/part2/heat_equation.py@@ -329,7 +329,7 @@ class BringTwoRodsTogether(Scene):else:return 10- def update_graph(self, graph, dt, alpha=None, n_mini_steps=100):+ def update_graph(self, graph, dt, alpha=None, n_mini_steps=500):if alpha is None:alpha = self.alphapoints = np.append(@@ -464,6 +464,7 @@ class ShowEvolvingTempGraphWithArrows(BringTwoRodsTogether):self.add_clock()self.add_rod()self.add_arrows()+ self.initialize_updaters()self.let_play()def add_axes(self):@@ -521,10 +522,9 @@ class ShowEvolvingTempGraphWithArrows(BringTwoRodsTogether):self.add(arrows)self.arrows = arrows- def let_play(self):+ def initialize_updaters(self):graph = self.graphrod = self.rod- clock = self.clocktime_label = self.time_labelgraph.add_updater(self.update_graph)@@ -533,6 +533,9 @@ class ShowEvolvingTempGraphWithArrows(BringTwoRodsTogether):)rod.add_updater(self.color_rod_by_graph)+ def let_play(self):+ clock = self.clock+# returnself.play(ClockPassesTime(diff --git a/active_projects/ode/part3/discrete_case.py b/active_projects/ode/part3/discrete_case.pynew file mode 100644index 000000000..09e64e0c0--- /dev/null+++ b/active_projects/ode/part3/discrete_case.py@@ -0,0 +1,7 @@+from manimlib.imports import *+from active_projects.ode.part2.heat_equation import *+++class NewSceneName(Scene):+ def construct(self):+ passdiff --git a/active_projects/ode/part3/pi_creature_scenes.py b/active_projects/ode/part3/pi_creature_scenes.pyindex 0d2e6a281..782496fd7 100644--- a/active_projects/ode/part3/pi_creature_scenes.py+++ b/active_projects/ode/part3/pi_creature_scenes.py@@ -125,7 +125,6 @@ class SineCurveIsUnrealistic(TeacherStudentsScene):self.wait(5)-class IfOnly(TeacherStudentsScene):def construct(self):self.teacher_says(diff --git a/active_projects/ode/part3/temperature_graphs.py b/active_projects/ode/part3/temperature_graphs.pyindex 0ccb811c9..853bc53e1 100644--- a/active_projects/ode/part3/temperature_graphs.py+++ b/active_projects/ode/part3/temperature_graphs.py@@ -164,6 +164,33 @@ class TemperatureGraphScene(SpecialThreeDScene):def get_rod_length(self):return self.axes_config["x_max"]+ def get_const_time_plane(self, axes):+ t_tracker = ValueTracker(0)+ plane = Polygon(+ *[+ axes.c2p(x, 0, z)+ for x, z in [+ (axes.x_min, axes.z_min),+ (axes.x_max, axes.z_min),+ (axes.x_max, axes.z_max),+ (axes.x_min, axes.z_max),+ ]+ ],+ stroke_width=0,+ fill_color=WHITE,+ fill_opacity=0.2+ )+ plane.add_updater(lambda m: m.move_to(+ axes.c2p(+ axes.x_min,+ t_tracker.get_value(),+ axes.z_min,+ ),+ IN + LEFT,+ ))+ plane.t_tracker = t_tracker+ return plane+class SimpleCosExpGraph(TemperatureGraphScene):def construct(self):@@ -1538,6 +1565,7 @@ class SimulateRealSineCurve(ShowEvolvingTempGraphWithArrows):self.add_clock()self.add_rod()self.add_arrows()+ self.initialize_updaters()self.let_play()def add_labels_to_axes(self):@@ -1572,6 +1600,64 @@ class SimulateRealSineCurve(ShowEvolvingTempGraphWithArrows):return temperature_to_color(0.8 * y)+class StraightLine3DGraph(TemperatureGraphScene):+ CONFIG = {+ "axes_config": {+ "z_min": 0,+ "z_max": 10,+ "z_axis_config": {+ 'unit_size': 0.5,+ }+ },+ "c": 1.2,+ }++ def construct(self):+ axes = self.get_three_d_axes()+ axes.add(axes.input_plane)+ axes.move_to(2 * IN + UP, IN)+ surface = self.get_surface(+ axes, self.func,+ )+ initial_graph = self.get_initial_state_graph(+ axes, lambda x: self.func(x, 0)+ )++ plane = self.get_const_time_plane(axes)+ initial_graph.add_updater(+ lambda m: m.move_to(plane, IN)+ )++ self.set_camera_orientation(+ phi=80 * DEGREES,+ theta=-100 * DEGREES,+ )+ self.begin_ambient_camera_rotation()++ self.add(axes)+ self.add(initial_graph)+ self.play(+ TransformFromCopy(initial_graph, surface)+ )+ self.add(surface, initial_graph)+ self.wait()++ self.play(+ FadeIn(plane),+ ApplyMethod(+ plane.t_tracker.set_value, 10,+ rate_func=linear,+ run_time=10,+ )+ )+ self.play(FadeOut(plane))+ self.wait(15)++ def func(self, x, t):+ return self.c * x+++class SimulateLinearGraph(SimulateRealSineCurve):CONFIG = {"axes_config": {@@ -1603,3 +1689,67 @@ class SimulateLinearGraph(SimulateRealSineCurve):x_max = axes.x_maxslope = y_max/ x_maxreturn slope * x+++class EmphasizeBoundaryPoints(SimulateLinearGraph):+ CONFIG = {+ "wait_time": 30,+ }++ def let_play(self):+ rod = self.rod+ self.graph.update(0.01)+ self.arrows.update()++ to_update = VGroup(+ self.graph,+ self.arrows,+ self.time_label,+ )+ for mob in to_update:+ mob.suspend_updating()++ dots = VGroup(+ Dot(rod.get_left()),+ Dot(rod.get_right()),+ )+ for dot in dots:+ dot.set_height(0.2)+ dot.set_color(YELLOW)++ words = TextMobject(+ "Different rules\\\\"+ "at the boundary"+ )+ words.next_to(rod, UP)++ arrows = VGroup(*[+ Arrow(+ words.get_corner(corner),+ dot.get_top(),+ path_arc=u * 60 * DEGREES,+ )+ for corner, dot, u in zip(+ [LEFT, RIGHT], dots, [1, -1]+ )+ ])++ self.add(words)+ self.play(+ LaggedStartMap(+ FadeInFromLarge, dots,+ scale_factor=5,+ ),+ LaggedStartMap(+ ShowCreation, arrows,+ ),+ lag_ratio=0.4+ )+ self.wait()++ for mob in to_update:+ mob.resume_updating()++ super().let_play()++diff --git a/active_projects/ode/part3/wordy_scenes.py b/active_projects/ode/part3/wordy_scenes.pyindex 2aac70930..559e5e4b2 100644--- a/active_projects/ode/part3/wordy_scenes.py+++ b/active_projects/ode/part3/wordy_scenes.py@@ -463,3 +463,81 @@ class ShowSinExpDerivatives(WriteHeatEquationTemplate):FadeOutAndShift(q_mark, UP))self.wait()+++class DerivativesOfLinearFunction(WriteHeatEquationTemplate):+ CONFIG = {+ "tex_mobject_config": {+ "tex_to_color_map": {+ "{c}": WHITE,+ }+ }+ }++ def construct(self):+ func = TexMobject(+ "T({x}, {t}) = {c} \\cdot {x}",+ **self.tex_mobject_config+ )+ dx_T = TexMobject("{c}", **self.tex_mobject_config)+ ddx_T = TexMobject("0")+ dt_T = TexMobject("0")++ for mob in func, dx_T, ddx_T, dt_T:+ mob.scale(1.5)++ func.generate_target()++ arrows = VGroup(*[+ Vector(1.5 * RIGHT, color=WHITE)+ for x in range(3)+ ])+ dx_arrows = arrows[:2]+ dt_arrow = arrows[2]+ dt_arrow.rotate(-TAU / 4)+ dx_group = VGroup(+ func.target,+ dx_arrows[0],+ dx_T,+ dx_arrows[1],+ ddx_T,+ )+ dx_group.arrange(RIGHT)+ for arrow, char, vect in zip(arrows, "xxt", [UP, UP, RIGHT]):+ label = TexMobject(+ "\\partial \\over \\partial {%s}"%char,+ **self.tex_mobject_config+ )+ label.scale(0.7)+ label.next_to(arrow.get_center(), vect)+ arrow.add(label)++ dt_arrow.shift(+ func.target[-3:].get_bottom() + MED_SMALL_BUFF * DOWN -+ dt_arrow.get_start(),+ )+ dt_T.next_to(dt_arrow.get_end(), DOWN)++ self.play(FadeInFromDown(func))+ self.wait()+ self.play(+ MoveToTarget(func),+ LaggedStartMap(Write, dx_arrows),+ run_time=1,+ )+ self.play(+ TransformFromCopy(func[-3:], dx_T),+ path_arc=-TAU / 4,+ )+ self.play(+ TransformFromCopy(dx_T, ddx_T),+ path_arc=-TAU / 4,+ )+ self.wait()++ # dt+ self.play(Write(dt_arrow))+ self.play(+ TransformFromCopy(func[-3:], dt_T)+ )+ self.wait()