From b6381972e776f13f0feae3d4b1e0cc9af36ae214 Mon Sep 17 00:00:00 2001 From: GoThrones Date: Wed, 6 May 2026 14:42:18 +0530 Subject: [PATCH 1/3] from main --- manim/animation/updaters/update.py | 88 ++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/manim/animation/updaters/update.py b/manim/animation/updaters/update.py index 29e636db5d..f0ce78966d 100644 --- a/manim/animation/updaters/update.py +++ b/manim/animation/updaters/update.py @@ -16,10 +16,44 @@ class UpdateFromFunc(Animation): - """ - update_function of the form func(mobject), presumably - to be used when the state of one mobject is dependent - on another simultaneously animated mobject + """ Updates the mobject based on an update_function of the form func(mobject). + + This can be used when the state of one mobject is dependent + on another simultaneously animated mobject. + + Parameters + ---------- + mobject + The mobject which needs to be updated. + + update_function + The function of the form func(mobject) + which would determine how the mobject is getting updated each frame. + + suspend_mobject_updating + If ``True``, any updater added via ``add_updater`` on the mobject + is suspended for the duration of this animation. Defaults to ``False``. + + **kwargs + Any other keyword arguments to be passed to :class:`Animation`. + + Example:: + + from manim import * + + class UpdateFromFuncDemo(Scene): + def construct(self): + dot = Dot().to_edge(1.5*LEFT) + label = Text("Hello").next_to(dot,UP) + + def update_func(mob): + mob.next_to(dot,UP) + + self.play( + dot.animate.to_edge(1.5*RIGHT), + UpdateFromFunc(label, update_func), + run_time=3, + ) """ def __init__( @@ -39,6 +73,52 @@ def interpolate_mobject(self, alpha: float) -> None: class UpdateFromAlphaFunc(UpdateFromFunc): + """ Updates the mobject based on an update_function of the form func(mobject, alpha). + + This can be used when the state of one mobject is dependent on: + (1) Another simultaneously animated mobject + (2) alpha value + + Parameters + ---------- + mobject + The mobject which needs to be updated. + + update_function + The function of the form func(mobject, alpha) + which would determine how the mobject is getting updated each frame. + + suspend_mobject_updating + If ``True``, any updater added via ``add_updater`` on the mobject + is suspended for the duration of this animation. Defaults to ``False``. + + **kwargs + Any other keyword arguments to be passed to :class:`Animation`. + + Example:: + + from manim import * + + class UpdateFromFuncDemo(Scene): + def construct(self): + dot = Dot().to_edge(1.5*LEFT) + label = Text("Hello").next_to(dot,UP) + number = DecimalNumber() + vg = VGroup(label, number) + self.add(vg) + + def update_func(mob, alpha): + m,n = mob + m.next_to(dot,UP) + m.set_opacity(alpha) + n.set_value(alpha).next_to(dot, DOWN) + + self.play( + dot.animate.to_edge(1.5*RIGHT), + UpdateFromAlphaFunc(vg, update_func), + run_time=3, + ) + """ def interpolate_mobject(self, alpha: float) -> None: self.update_function(self.mobject, self.rate_func(alpha)) # type: ignore[call-arg, arg-type] From b16f873e0b1414141634c58f3cc72f1df1b43d93 Mon Sep 17 00:00:00 2001 From: GoThrones Date: Wed, 6 May 2026 15:11:17 +0530 Subject: [PATCH 2/3] added docstring to update.py --- manim/animation/updaters/update.py | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/manim/animation/updaters/update.py b/manim/animation/updaters/update.py index f0ce78966d..fcbd1211b5 100644 --- a/manim/animation/updaters/update.py +++ b/manim/animation/updaters/update.py @@ -99,7 +99,7 @@ class UpdateFromAlphaFunc(UpdateFromFunc): from manim import * - class UpdateFromFuncDemo(Scene): + class UpdateFromAlphaFuncDemo(Scene): def construct(self): dot = Dot().to_edge(1.5*LEFT) label = Text("Hello").next_to(dot,UP) @@ -124,6 +124,33 @@ def interpolate_mobject(self, alpha: float) -> None: class MaintainPositionRelativeTo(Animation): + """ Useful when one mobject's position is to be maintained constant w.r.t another mobject's position. + + Parameters + ---------- + mobject + The mobject whose position is to be kept constant w.r.t another mobject + tracked_mobject + This is the mobject w.r.t whose position, the mobject's position is to be kept constant. + **kwargs + Any other keyword arguments to be passed to :class:`Animation`. + + Example:: + + from manim import * + + class MaintainPositionRelativeToDemo(Scene): + def construct(self): + dot = Dot().to_edge(1.5*LEFT) + label = Text("Hello").next_to(dot,UP) + + self.play( + dot.animate.to_edge(1.5*RIGHT), + MaintainPositionRelativeTo(label, dot), + run_time=3, + ) + + """ def __init__( self, mobject: Mobject, tracked_mobject: Mobject, **kwargs: Any ) -> None: @@ -137,4 +164,4 @@ def __init__( def interpolate_mobject(self, alpha: float) -> None: target = self.tracked_mobject.get_center() location = self.mobject.get_center() - self.mobject.shift(target - location + self.diff) + self.mobject.shift(target + self.diff - location) From 9728c8865e41e0179da1ac86ee96a1e756174ae5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 May 2026 09:43:16 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/animation/updaters/update.py | 61 ++++++++++++++++-------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/manim/animation/updaters/update.py b/manim/animation/updaters/update.py index fcbd1211b5..3adb8adefa 100644 --- a/manim/animation/updaters/update.py +++ b/manim/animation/updaters/update.py @@ -16,8 +16,8 @@ class UpdateFromFunc(Animation): - """ Updates the mobject based on an update_function of the form func(mobject). - + """Updates the mobject based on an update_function of the form func(mobject). + This can be used when the state of one mobject is dependent on another simultaneously animated mobject. @@ -27,13 +27,13 @@ class UpdateFromFunc(Animation): The mobject which needs to be updated. update_function - The function of the form func(mobject) + The function of the form func(mobject) which would determine how the mobject is getting updated each frame. - + suspend_mobject_updating If ``True``, any updater added via ``add_updater`` on the mobject is suspended for the duration of this animation. Defaults to ``False``. - + **kwargs Any other keyword arguments to be passed to :class:`Animation`. @@ -41,16 +41,17 @@ class UpdateFromFunc(Animation): from manim import * + class UpdateFromFuncDemo(Scene): - def construct(self): - dot = Dot().to_edge(1.5*LEFT) - label = Text("Hello").next_to(dot,UP) + def construct(self): + dot = Dot().to_edge(1.5 * LEFT) + label = Text("Hello").next_to(dot, UP) def update_func(mob): - mob.next_to(dot,UP) + mob.next_to(dot, UP) self.play( - dot.animate.to_edge(1.5*RIGHT), + dot.animate.to_edge(1.5 * RIGHT), UpdateFromFunc(label, update_func), run_time=3, ) @@ -73,8 +74,8 @@ def interpolate_mobject(self, alpha: float) -> None: class UpdateFromAlphaFunc(UpdateFromFunc): - """ Updates the mobject based on an update_function of the form func(mobject, alpha). - + """Updates the mobject based on an update_function of the form func(mobject, alpha). + This can be used when the state of one mobject is dependent on: (1) Another simultaneously animated mobject (2) alpha value @@ -85,13 +86,13 @@ class UpdateFromAlphaFunc(UpdateFromFunc): The mobject which needs to be updated. update_function - The function of the form func(mobject, alpha) + The function of the form func(mobject, alpha) which would determine how the mobject is getting updated each frame. - + suspend_mobject_updating If ``True``, any updater added via ``add_updater`` on the mobject is suspended for the duration of this animation. Defaults to ``False``. - + **kwargs Any other keyword arguments to be passed to :class:`Animation`. @@ -99,32 +100,34 @@ class UpdateFromAlphaFunc(UpdateFromFunc): from manim import * + class UpdateFromAlphaFuncDemo(Scene): - def construct(self): - dot = Dot().to_edge(1.5*LEFT) - label = Text("Hello").next_to(dot,UP) - number = DecimalNumber() + def construct(self): + dot = Dot().to_edge(1.5 * LEFT) + label = Text("Hello").next_to(dot, UP) + number = DecimalNumber() vg = VGroup(label, number) self.add(vg) def update_func(mob, alpha): - m,n = mob - m.next_to(dot,UP) + m, n = mob + m.next_to(dot, UP) m.set_opacity(alpha) n.set_value(alpha).next_to(dot, DOWN) self.play( - dot.animate.to_edge(1.5*RIGHT), + dot.animate.to_edge(1.5 * RIGHT), UpdateFromAlphaFunc(vg, update_func), run_time=3, ) """ + def interpolate_mobject(self, alpha: float) -> None: self.update_function(self.mobject, self.rate_func(alpha)) # type: ignore[call-arg, arg-type] class MaintainPositionRelativeTo(Animation): - """ Useful when one mobject's position is to be maintained constant w.r.t another mobject's position. + """Useful when one mobject's position is to be maintained constant w.r.t another mobject's position. Parameters ---------- @@ -134,23 +137,25 @@ class MaintainPositionRelativeTo(Animation): This is the mobject w.r.t whose position, the mobject's position is to be kept constant. **kwargs Any other keyword arguments to be passed to :class:`Animation`. - + Example:: from manim import * + class MaintainPositionRelativeToDemo(Scene): - def construct(self): - dot = Dot().to_edge(1.5*LEFT) - label = Text("Hello").next_to(dot,UP) + def construct(self): + dot = Dot().to_edge(1.5 * LEFT) + label = Text("Hello").next_to(dot, UP) self.play( - dot.animate.to_edge(1.5*RIGHT), + dot.animate.to_edge(1.5 * RIGHT), MaintainPositionRelativeTo(label, dot), run_time=3, ) """ + def __init__( self, mobject: Mobject, tracked_mobject: Mobject, **kwargs: Any ) -> None: