Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 29, 2024
1 parent e2df7df commit cff2181
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
37 changes: 37 additions & 0 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from manim import config, logger
from manim.constants import *
from manim.mobject.builders import _UpdaterBuilder

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
'_UpdaterBuilder' may not be defined if module
manim.mobject.builders
is imported before module
manim.mobject.opengl.opengl_mobject
, as the
definition
of _UpdaterBuilder occurs after the cyclic
import
of manim.mobject.opengl.opengl_mobject.
from manim.renderer.shader_wrapper import get_colormap_code
from manim.utils.bezier import integer_interpolate, interpolate
from manim.utils.color import (
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cff2181

Please sign in to comment.