From cff218180778b036e7ffddb94eec86c978a15918 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Tue, 29 Oct 2024 19:27:13 -0400 Subject: [PATCH] updated docs --- manim/mobject/mobject.py | 6 +++++ manim/mobject/opengl/opengl_mobject.py | 37 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index 8cbc38f2d0..fbc704c069 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -406,6 +406,12 @@ def always(self) -> Self: as its own updater. If you are chaining methods, make sure they do not interfere with each other or you may get unexpected results. + .. warning:: + + :attr:`always` is not compatible with :meth:`.ValueTracker.get_value`, because + the value will be computed once and then never updated again. Use :meth:`add_updater` + if you would like to use a :class:`~.ValueTracker` to update the value. + Example ------- diff --git a/manim/mobject/opengl/opengl_mobject.py b/manim/mobject/opengl/opengl_mobject.py index 1f7d44d6a3..ad721c7d86 100644 --- a/manim/mobject/opengl/opengl_mobject.py +++ b/manim/mobject/opengl/opengl_mobject.py @@ -16,6 +16,7 @@ from manim import config, logger from manim.constants import * +from manim.mobject.builders import _UpdaterBuilder from manim.renderer.shader_wrapper import get_colormap_code from manim.utils.bezier import integer_interpolate, interpolate from manim.utils.color import ( @@ -474,6 +475,42 @@ def construct(self): """ return _AnimationBuilder(self) + @property + def always(self) -> Self: + """Call a method on a mobject every frame. + + This is syntactic sugar for ``mob.add_updater(lambda m: m.method(*args, **kwargs), call_updater=True)``. + Note that this will call the method immediately. If this behavior is not + desired, you should use :meth:`add_updater` directly. + + .. warning:: + + Chaining of methods is allowed, but each method will be added + as its own updater. If you are chaining methods, make sure they + do not interfere with each other or you may get unexpected results. + + .. warning:: + + :attr:`always` is not compatible with :meth:`.ValueTracker.get_value`, because + the value will be computed once and then never updated again. Use :meth:`add_updater` + if you would like to use a :class:`~.ValueTracker` to update the value. + + Example + ------- + + .. manim:: AlwaysExample + + class AlwaysExample(Scene): + def construct(self): + sq = Square().to_edge(LEFT) + t = Text("Hello World!") + t.always.next_to(sq, UP) + self.add(sq, t) + self.play(sq.animate.to_edge(RIGHT)) + """ + # can't use typing.cast because Self is under TYPE_CHECKING + return _UpdaterBuilder(self) # type: ignore[misc] + @property def width(self) -> float: """The width of the mobject.