A community-maintained Python framework for creating mathematical animations.
updating_mobject_from_func -> always_redraw
Grant Sanderson94d7a8a663d6
diff --git a/active_projects/shadows.py b/active_projects/shadows.pyindex 3d80f9bdd..c9e14601c 100644--- a/active_projects/shadows.py+++ b/active_projects/shadows.py@@ -99,8 +99,8 @@ class ShowShadows(ThreeDScene):self.gamma_tracker = ValueTracker(0)def setup_object_and_shadow(self):- self.obj3d = updating_mobject_from_func(self.get_reoriented_object)- self.shadow = updating_mobject_from_func(lambda: get_shadow(self.obj3d))+ self.obj3d = always_redraw(self.get_reoriented_object)+ self.shadow = always_redraw(lambda: get_shadow(self.obj3d))def add_shadow_area_label(self):text = TextMobject("Shadow area: ")@@ -145,7 +145,7 @@ class ShowShadows(ThreeDScene):# Show creationobj3d = self.obj3d.copy()obj3d.clear_updaters()- temp_shadow = updating_mobject_from_func(lambda: get_shadow(obj3d))+ temp_shadow = always_redraw(lambda: get_shadow(obj3d))self.add(temp_shadow)self.move_camera(**self.initial_orientation_config,diff --git a/manimlib/animation/indication.py b/manimlib/animation/indication.pyindex 2e7a874a0..9fb1f2470 100644--- a/manimlib/animation/indication.py+++ b/manimlib/animation/indication.py@@ -13,7 +13,7 @@ from manimlib.animation.fading import FadeInfrom manimlib.animation.fading import FadeOutfrom manimlib.animation.transform import Transformfrom manimlib.animation.update import UpdateFromAlphaFunc-from manimlib.mobject.mobject_update_utils import updating_mobject_from_func+from manimlib.mobject.mobject_update_utils import always_redrawfrom manimlib.mobject.mobject import Mobjectfrom manimlib.mobject.types.vectorized_mobject import VMobjectfrom manimlib.mobject.geometry import Circlediff --git a/manimlib/mobject/mobject_update_utils.py b/manimlib/mobject/mobject_update_utils.pyindex e3e4e7b3c..e1a498d8b 100644--- a/manimlib/mobject/mobject_update_utils.py+++ b/manimlib/mobject/mobject_update_utils.py@@ -1,4 +1,4 @@-def updating_mobject_from_func(func):+def always_redraw(func):mob = func()mob.add_updater(lambda m: mob.become(func()))return mobdiff --git a/old_projects/borsuk_addition.py b/old_projects/borsuk_addition.pyindex 6d01fb6c3..9c3bcae17 100644--- a/old_projects/borsuk_addition.py+++ b/old_projects/borsuk_addition.py@@ -106,7 +106,7 @@ class UnexpectedConnection(Scene):stroke_width=5).shift(center)- arc = updating_mobject_from_func(get_arc)+ arc = always_redraw(get_arc)decimal = DecimalNumber(0)decimal.add_updater(@@ -613,7 +613,7 @@ class FunctionGInputSpace(SpecialThreeDScene):def show_antipodal_point(self):path = self.get_antipodal_path()- end_dot = updating_mobject_from_func(+ end_dot = always_redraw(lambda: self.get_dot(path[-1].point_from_proportion(1)).set_color(RED)@@ -701,7 +701,7 @@ class FunctionGInputSpace(SpecialThreeDScene):self.add(self.tracked_point)def init_dot(self):- self.dot = updating_mobject_from_func(+ self.dot = always_redraw(lambda: self.get_dot(self.tracked_point.get_center()))diff --git a/old_projects/clacks/solution1.py b/old_projects/clacks/solution1.pyindex af0034ed7..06f538697 100644--- a/old_projects/clacks/solution1.py+++ b/old_projects/clacks/solution1.py@@ -2055,7 +2055,7 @@ class AddTwoThetaManyTimes(Scene):result[1].scale(1.5, about_edge=LEFT)return result- comp_pi = updating_mobject_from_func(get_comp_pi)+ comp_pi = always_redraw(get_comp_pi)return VGroup(int_mob, tex_mob, rhs, comp_pi)@@ -2548,7 +2548,7 @@ class ActanAndTanGraphs(GraphScene):label.next_to(graph.point_from_proportion(0.75), LEFT)arctan_x_tracker = ValueTracker(3 * PI / 8)- arctan_v_line = updating_mobject_from_func(+ arctan_v_line = always_redraw(lambda: self.get_vertical_line_to_graph(arctan_x_tracker.get_value(),arctan_graph,@@ -2557,7 +2557,7 @@ class ActanAndTanGraphs(GraphScene):))tan_x_tracker = ValueTracker(2 * PI / 8)- tan_v_line = updating_mobject_from_func(+ tan_v_line = always_redraw(lambda: self.get_vertical_line_to_graph(tan_x_tracker.get_value(),tan_graph,@@ -2643,7 +2643,7 @@ class UnitCircleIntuition(Scene):circle.get_center(),circle.point_at_angle(get_theta()))- r_line = updating_mobject_from_func(get_r_line)+ r_line = always_redraw(get_r_line)def get_arc(radius=None, **kwargs):if radius is None:@@ -2656,8 +2656,8 @@ class UnitCircleIntuition(Scene):arc_center=circle.get_center(),**kwargs)- arc = updating_mobject_from_func(get_arc)- self.circle_arc = updating_mobject_from_func(+ arc = always_redraw(get_arc)+ self.circle_arc = always_redraw(lambda: get_arc(radius=circle.radius, color=RED))@@ -2670,7 +2670,7 @@ class UnitCircleIntuition(Scene):vect = (get_norm(vect) + 2 * SMALL_BUFF) * normalize(vect)label.move_to(center + vect)return label- theta_label = updating_mobject_from_func(get_theta_label)+ theta_label = always_redraw(get_theta_label)def get_height_line():p2 = circle.point_at_angle(get_theta())@@ -2681,7 +2681,7 @@ class UnitCircleIntuition(Scene):stroke_color=YELLOW,stroke_width=3,)- self.height_line = updating_mobject_from_func(get_height_line)+ self.height_line = always_redraw(get_height_line)def get_width_line():p2 = circle.get_center()@@ -2692,7 +2692,7 @@ class UnitCircleIntuition(Scene):stroke_color=PINK,stroke_width=3,)- self.width_line = updating_mobject_from_func(get_width_line)+ self.width_line = always_redraw(get_width_line)def get_h_label():label = TexMobject("h")@@ -2702,7 +2702,7 @@ class UnitCircleIntuition(Scene):label.set_stroke(BLACK, 3, background=True)label.next_to(height_line, RIGHT, SMALL_BUFF)return label- self.h_label = updating_mobject_from_func(get_h_label)+ self.h_label = always_redraw(get_h_label)def get_w_label():label = TexMobject("w")@@ -2710,7 +2710,7 @@ class UnitCircleIntuition(Scene):label.match_color(width_line)label.next_to(width_line, DOWN, SMALL_BUFF)return label- self.w_label = updating_mobject_from_func(get_w_label)+ self.w_label = always_redraw(get_w_label)self.add(r_line, theta_label, arc, self.radius_line)self.play(diff --git a/old_projects/clacks/solution2/mirror_scenes.py b/old_projects/clacks/solution2/mirror_scenes.pyindex 4bfbe36c8..7c6363e1c 100644--- a/old_projects/clacks/solution2/mirror_scenes.py+++ b/old_projects/clacks/solution2/mirror_scenes.py@@ -99,7 +99,7 @@ class MirrorScene(Scene):return mirrorsdef get_arc(self, radius=0.5):- return updating_mobject_from_func(lambda: Arc(+ return always_redraw(lambda: Arc(start_angle=0,angle=self.get_theta(),arc_center=self.get_center(),@@ -483,7 +483,7 @@ class ReflectWorldThroughMirrorNew(MirrorScene):rw[0].set_fill(opacity=0.25)def create_reflected_trajectories(self):- self.reflected_trajectories = updating_mobject_from_func(+ self.reflected_trajectories = always_redraw(lambda: self.get_reflected_worlds(self.trajectory))@@ -951,7 +951,7 @@ class MirrorAndWiresOverlay(MirrorScene):angle=dl_wire.get_angle(),**arc_config,)- dl_arc = updating_mobject_from_func(get_dl_arc)+ dl_arc = always_redraw(get_dl_arc)def get_dr_arc():return Arc(@@ -959,7 +959,7 @@ class MirrorAndWiresOverlay(MirrorScene):angle=dr_wire.get_angle() - PI,**arc_config,)- dr_arc = updating_mobject_from_func(get_dr_arc)+ dr_arc = always_redraw(get_dr_arc)incidence = TextMobject("Incidence")reflection = TextMobject("Reflection")diff --git a/old_projects/clacks/solution2/position_phase_space.py b/old_projects/clacks/solution2/position_phase_space.pyindex 5cc15ca93..b87d190a5 100644--- a/old_projects/clacks/solution2/position_phase_space.py+++ b/old_projects/clacks/solution2/position_phase_space.py@@ -470,7 +470,7 @@ class PositionPhaseSpaceScene(Scene):y_axis_point, point,**self.ps_x_line_config,)- self.x_line = updating_mobject_from_func(get_x_line)+ self.x_line = always_redraw(get_x_line)return self.x_linedef get_phase_space_y_line(self):@@ -483,7 +483,7 @@ class PositionPhaseSpaceScene(Scene):x_axis_point, point,**self.ps_y_line_config,)- self.y_line = updating_mobject_from_func(get_y_line)+ self.y_line = always_redraw(get_y_line)return self.y_linedef get_phase_space_dot(self):@@ -541,7 +541,7 @@ class PositionPhaseSpaceScene(Scene):line.put_start_and_end_on(left_point, right_point)return Brace(line, UP, buff=SMALL_BUFF)- brace = updating_mobject_from_func(get_brace)+ brace = always_redraw(get_brace)return bracedef get_d1_brace(self):diff --git a/old_projects/clacks/solution2/simple_scenes.py b/old_projects/clacks/solution2/simple_scenes.pyindex de19b8cd3..530c0c4ff 100644--- a/old_projects/clacks/solution2/simple_scenes.py+++ b/old_projects/clacks/solution2/simple_scenes.py@@ -161,7 +161,7 @@ class ShowDotProductMeaning(Scene):stroke_color=LIGHT_GREY,stroke_width=1,)- w_line = updating_mobject_from_func(get_w_line)+ w_line = always_redraw(get_w_line)def get_proj_v():center = dot.get_center()@@ -172,7 +172,7 @@ class ShowDotProductMeaning(Scene):result.set_fill(v_vect.get_color(), 0.5)result.shift(center - result.get_start())return result- proj_v = updating_mobject_from_func(get_proj_v)+ proj_v = always_redraw(get_proj_v)def get_proj_line():return DashedLine(@@ -181,7 +181,7 @@ class ShowDotProductMeaning(Scene):stroke_width=1,dash_length=0.025,)- proj_line = updating_mobject_from_func(get_proj_line)+ proj_line = always_redraw(get_proj_line)template_line = Line(LEFT, RIGHT)@@ -194,10 +194,10 @@ class ShowDotProductMeaning(Scene):brace.rotate(angle, about_point=ORIGIN)brace.shift(vect.get_center())return brace- w_brace = updating_mobject_from_func(+ w_brace = always_redraw(lambda: get_vect_brace(w_vect))- proj_v_brace = updating_mobject_from_func(+ proj_v_brace = always_redraw(lambda: get_vect_brace(proj_v))@@ -217,7 +217,7 @@ class ShowDotProductMeaning(Scene):center + 1.5 * (p - center))return VGroup(arc, theta)- arc = updating_mobject_from_func(get_arc)+ arc = always_redraw(get_arc)self.add(title[:3],@@ -464,7 +464,7 @@ class AskAboutAddingThetaToItself(Scene):result.set_color(get_color())result.move_to(ineq)return result- dynamic_ineq = updating_mobject_from_func(get_ineq)+ dynamic_ineq = always_redraw(get_ineq)group.remove(ineq)group.add(dynamic_ineq)diff --git a/old_projects/quat3d.py b/old_projects/quat3d.pyindex 9e9ece25b..7f20ff9d7 100644--- a/old_projects/quat3d.py+++ b/old_projects/quat3d.py@@ -455,7 +455,7 @@ class ShowSeveralQuaternionRotations(SpecialThreeDScene):self.add(prism)def add_axes(self):- axes = self.axes = updating_mobject_from_func(self.get_axes)+ axes = self.axes = always_redraw(self.get_axes)self.add(axes)def apply_quaternions(self):@@ -659,7 +659,7 @@ class EulerAnglesAndGimbal(ShowSeveralQuaternionRotations):self.gamma_tracker = ValueTracker(0)def setup_gimbal(self):- gimbal = updating_mobject_from_func(self.get_gimbal)+ gimbal = always_redraw(self.get_gimbal)self.gimbal = gimbalself.add(gimbal)@@ -1245,7 +1245,7 @@ class RuleForQuaternionRotations(EulerAnglesAndGimbal):result.rotate(angle=angle, axis=axis, about_point=ORIGIN)return result- sphere = updating_mobject_from_func(get_sphere)+ sphere = always_redraw(get_sphere)point_label = TexMobject("p", "=",diff --git a/old_projects/quaternions.py b/old_projects/quaternions.pyindex 11f050598..17a7ec2c4 100644--- a/old_projects/quaternions.py+++ b/old_projects/quaternions.py@@ -2832,7 +2832,7 @@ class ShowRotationUnderStereographicProjection(IntroduceStereographicProjection)neg_one_dot = Dot(neg_one_point)neg_one_dot.set_fill(YELLOW)- lines = updating_mobject_from_func(self.get_lines)+ lines = always_redraw(self.get_lines)def generate_dot_updater(circle_piece):return lambda d: d.move_to(circle_piece.points[0])diff --git a/old_projects/sphere_area.py b/old_projects/sphere_area.pyindex 3e3ffb638..7d7831c9a 100644--- a/old_projects/sphere_area.py+++ b/old_projects/sphere_area.py@@ -582,7 +582,7 @@ class UnfoldCircles(Scene):unwrap_factor_tracker = ValueTracker(0)def get_circle(line):- return updating_mobject_from_func(+ return always_redraw(lambda: self.get_unwrapped_circle(radius=radius, dr=self.dr,unwrap_factor=unwrap_factor_tracker.get_value(),@@ -1073,7 +1073,7 @@ class SlantedShadowSquishing(ShowShadows):self.begin_ambient_camera_rotation(0.01)square = self.obj3d.deepcopy()square.clear_updaters()- shadow = updating_mobject_from_func(lambda: get_shadow(square))+ shadow = always_redraw(lambda: get_shadow(square))# Reorientself.add(square, shadow)@@ -1998,13 +1998,13 @@ class SameEffectAsRotating(Scene):group.center()moving_rect = rect1.copy()- low_brace = updating_mobject_from_func(+ low_brace = always_redraw(lambda: Brace(moving_rect, DOWN, buff=SMALL_BUFF,min_num_quads=2,))- right_brace = updating_mobject_from_func(+ right_brace = always_redraw(lambda: Brace(moving_rect, RIGHT, buff=SMALL_BUFF,min_num_quads=2,@@ -2331,7 +2331,7 @@ class WhatIsSurfaceArea(SpecialThreeDScene):self.add_fixed_in_frame_mobjects(title)power_tracker = ValueTracker(1)- surface = updating_mobject_from_func(+ surface = always_redraw(lambda: self.get_surface(radius=3,amplitude=1,@@ -2484,7 +2484,7 @@ class UnwrappedCircleLogic(UnfoldCircles):).set_stroke(YELLOW, 2)return result- unwrapped_circle = updating_mobject_from_func(get_unwrapped_circle)+ unwrapped_circle = always_redraw(get_unwrapped_circle)circle = unwrapped_circle.copy()circle.clear_updaters()R_line = Line(circle.get_center(), circle.get_bottom())@@ -2493,7 +2493,7 @@ class UnwrappedCircleLogic(UnfoldCircles):R_label.next_to(R_line, LEFT)circle_group = VGroup(circle, R_line, R_label)- tri_R_line = updating_mobject_from_func(+ tri_R_line = always_redraw(lambda: Line(ORIGIN, radius * DOWN).shift(center_tracker.get_center())@@ -2515,7 +2515,7 @@ class UnwrappedCircleLogic(UnfoldCircles):self.wait()# Change radius- r_line = updating_mobject_from_func(+ r_line = always_redraw(lambda: Line(ORIGIN, get_r() * DOWN,stroke_width=2,@@ -2930,7 +2930,7 @@ class SecondProof(SpecialThreeDScene):def show_theta(self):theta_tracker = ValueTracker(0)get_theta = theta_tracker.get_value- theta_group = updating_mobject_from_func(+ theta_group = always_redraw(lambda: self.get_theta_group(get_theta()))theta_mob_opacity_tracker = ValueTracker(0)@@ -2945,7 +2945,7 @@ class SecondProof(SpecialThreeDScene):))- lit_ring = updating_mobject_from_func(+ lit_ring = always_redraw(lambda: self.get_ring_from_theta(self.rings, get_theta()).copy().set_color(YELLOW)@@ -3113,7 +3113,7 @@ class SecondProof(SpecialThreeDScene):def ask_about_2_to_1_correspondance(self):theta_tracker = ValueTracker(0)get_theta = theta_tracker.get_value- new_lit_ring = updating_mobject_from_func(+ new_lit_ring = always_redraw(lambda: self.get_ring_from_theta(self.rings, get_theta()).copy().set_color(PINK)