From 19828ac2c9947245189ddef497963c421cbdc894 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 4 Aug 2023 15:30:27 -0400 Subject: [PATCH 1/9] Added docstring & example for always_redraw --- .../updaters/mobject_update_utils.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index c77174c89c..7d798eb253 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -56,8 +56,33 @@ def updater(mob): def always_redraw(func): + """Always redraw a mobject + + .. manim:: TangentAnimation + + class TangentAnimation(Scene): + def construct(self): + ax = Axes() + sine = ax.plot(np.sin, color=RED) + alpha = ValueTracker(0) + d = Dot(color=BLUE) + d.add_updater( + lambda m: m.move_to( + sine.point_from_proportion(alpha.get_value())), + call_updater=True + ) + t = always_redraw( + lambda: TangentLine( + sine, + alpha=alpha.get_value(), + color=YELLOW, + length=4) + ) + self.play(Create(ax), Create(sine), Create(d), Create(t)) + self.play(alpha.animate.set_value(1), rate_func=linear, run_time=10) + """ mob = func() - mob.add_updater(lambda m: mob.become(func())) + mob.add_updater(lambda _: mob.become(func())) return mob From 46a3e70bb17924377731158a202051dcc34606e4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Aug 2023 19:34:12 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/animation/updaters/mobject_update_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index 7d798eb253..b651a49526 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -57,7 +57,7 @@ def updater(mob): def always_redraw(func): """Always redraw a mobject - + .. manim:: TangentAnimation class TangentAnimation(Scene): From 215521ca28cafd6ae1cf7e6ff366f16363efe0c3 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 4 Aug 2023 16:40:42 -0400 Subject: [PATCH 3/9] made more descriptive names for vars in example --- .../animation/updaters/mobject_update_utils.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index b651a49526..1d4b3ccb70 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -56,7 +56,7 @@ def updater(mob): def always_redraw(func): - """Always redraw a mobject + """Redraw a mobject every frame. .. manim:: TangentAnimation @@ -65,20 +65,19 @@ def construct(self): ax = Axes() sine = ax.plot(np.sin, color=RED) alpha = ValueTracker(0) - d = Dot(color=BLUE) - d.add_updater( - lambda m: m.move_to( - sine.point_from_proportion(alpha.get_value())), - call_updater=True - ) - t = always_redraw( + point = always_redraw( + lambda: Dot( + sine.point_from_proportion(alpha.get_value()), + color=BLUE) + ) + tangent = always_redraw( lambda: TangentLine( sine, alpha=alpha.get_value(), color=YELLOW, length=4) ) - self.play(Create(ax), Create(sine), Create(d), Create(t)) + self.play(Create(ax), Create(sine), Create(point), Create(tangent)) self.play(alpha.animate.set_value(1), rate_func=linear, run_time=10) """ mob = func() From 2bfa9313ad9e3606c9b3e0f846d72317f7e2d33a Mon Sep 17 00:00:00 2001 From: Jason Grace <110117391+JasonGrace2282@users.noreply.github.com> Date: Fri, 4 Aug 2023 19:44:17 -0400 Subject: [PATCH 4/9] Change runtime 10s->3s Co-authored-by: Jason Villanueva --- manim/animation/updaters/mobject_update_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index 1d4b3ccb70..b8b5f2d716 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -78,7 +78,7 @@ def construct(self): length=4) ) self.play(Create(ax), Create(sine), Create(point), Create(tangent)) - self.play(alpha.animate.set_value(1), rate_func=linear, run_time=10) + self.play(alpha.animate.set_value(1), rate_func=linear, run_time=3) """ mob = func() mob.add_updater(lambda _: mob.become(func())) From 0103fa146bd3d204d31029612ddb4f53491e1d21 Mon Sep 17 00:00:00 2001 From: Jason Grace <110117391+JasonGrace2282@users.noreply.github.com> Date: Sat, 5 Aug 2023 09:06:59 -0400 Subject: [PATCH 5/9] change Create -> add Co-authored-by: Benjamin Hackl --- manim/animation/updaters/mobject_update_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index b8b5f2d716..c4d8835884 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -77,8 +77,8 @@ def construct(self): color=YELLOW, length=4) ) - self.play(Create(ax), Create(sine), Create(point), Create(tangent)) - self.play(alpha.animate.set_value(1), rate_func=linear, run_time=3) + self.add(ax, sine, point, tangent) + self.play(alpha.animate.set_value(1), rate_func=linear, run_time=2) """ mob = func() mob.add_updater(lambda _: mob.become(func())) From 761ead3f2f4dc85c67f4567897dbec517284e0fe Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Sat, 5 Aug 2023 09:08:07 -0400 Subject: [PATCH 6/9] Added typehint for always_redraw --- manim/animation/updaters/mobject_update_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index b8b5f2d716..26e55dcc0f 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -18,6 +18,8 @@ import numpy as np +from collections.abc import Callable + from manim.constants import DEGREES, RIGHT from manim.mobject.mobject import Mobject from manim.opengl import OpenGLMobject @@ -55,7 +57,7 @@ def updater(mob): return mobject -def always_redraw(func): +def always_redraw(func: Callable[[], Mobject]): """Redraw a mobject every frame. .. manim:: TangentAnimation From f0f6540bb0b1ff496a86c1a98fdeaea5890ffdfb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:08:45 +0000 Subject: [PATCH 7/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim/animation/updaters/mobject_update_utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index d35b0f9119..04cd2e0588 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -15,11 +15,10 @@ import inspect +from collections.abc import Callable import numpy as np -from collections.abc import Callable - from manim.constants import DEGREES, RIGHT from manim.mobject.mobject import Mobject from manim.opengl import OpenGLMobject From fa5930f7ef12518aa82838eaadb24fc68c323f04 Mon Sep 17 00:00:00 2001 From: Jason Grace <110117391+JasonGrace2282@users.noreply.github.com> Date: Sun, 6 Aug 2023 17:52:39 -0400 Subject: [PATCH 8/9] Changed description of :meth:`always_redraw` Co-authored-by: Benjamin Hackl --- manim/animation/updaters/mobject_update_utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index 04cd2e0588..c8ab751887 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -57,7 +57,20 @@ def updater(mob): def always_redraw(func: Callable[[], Mobject]): - """Redraw a mobject every frame. + """Redraw the mobject constructed by a function every frame. + + This function returns a mobject with an attached updater that + continuously regenerates the mobject according to the + specified function. + + Parameters + ---------- + func + A function without (required) input arguments that returns + a mobject. + + Examples + -------- .. manim:: TangentAnimation From 0a5637ac1550a68c591f85c0052bb529105d90ab Mon Sep 17 00:00:00 2001 From: Jason Grace <110117391+JasonGrace2282@users.noreply.github.com> Date: Sun, 6 Aug 2023 17:52:59 -0400 Subject: [PATCH 9/9] Added return type to :meth:`always_redraw` Co-authored-by: Benjamin Hackl --- manim/animation/updaters/mobject_update_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/animation/updaters/mobject_update_utils.py b/manim/animation/updaters/mobject_update_utils.py index c8ab751887..698dc03d56 100644 --- a/manim/animation/updaters/mobject_update_utils.py +++ b/manim/animation/updaters/mobject_update_utils.py @@ -56,7 +56,7 @@ def updater(mob): return mobject -def always_redraw(func: Callable[[], Mobject]): +def always_redraw(func: Callable[[], Mobject]) -> Mobject: """Redraw the mobject constructed by a function every frame. This function returns a mobject with an attached updater that