Skip to content

Commit

Permalink
Merge pull request 3b1b#1862 from widcardw/dev
Browse files Browse the repository at this point in the history
Add `set_anim_args` to `.animate` method
  • Loading branch information
3b1b authored Sep 13, 2022
2 parents d48957c + 603a773 commit d2e570e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions manimlib/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def check_validity_of_input(self, mobject: Mobject) -> None:


class _MethodAnimation(MoveToTarget):
def __init__(self, mobject: Mobject, methods: Callable):
def __init__(self, mobject: Mobject, methods: list[Callable], **kwargs):
self.methods = methods
super().__init__(mobject)
super().__init__(mobject, **kwargs)


class ApplyMethod(Transform):
Expand Down
33 changes: 31 additions & 2 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,9 @@ def __init__(self, mobject: Mobject):
self.overridden_animation = None
self.mobject.generate_target()
self.is_chaining = False
self.methods = []
self.methods: list[Callable] = []
self.anim_args = {}
self.can_pass_args = True

def __getattr__(self, method_name: str):
method = getattr(self.mobject.target, method_name)
Expand All @@ -2040,13 +2042,40 @@ def update_target(*method_args, **method_kwargs):
self.is_chaining = True
return update_target

def __call__(self, **kwargs):
return self.set_anim_args(**kwargs)

def set_anim_args(self, **kwargs):
'''
You can change the args of :class:`~manimlib.animation.transform.Transform`, such as
- ``run_time``
- ``time_span``
- ``rate_func``
- ``lag_ratio``
- ``path_arc``
- ``path_func``
and so on.
'''

if not self.can_pass_args:
raise ValueError(
"Animation arguments can only be passed by calling ``animate`` "
"or ``set_anim_args`` and can only be passed once",
)

self.anim_args = kwargs
self.can_pass_args = False
return self

def build(self):
from manimlib.animation.transform import _MethodAnimation

if self.overridden_animation:
return self.overridden_animation

return _MethodAnimation(self.mobject, self.methods)
return _MethodAnimation(self.mobject, self.methods, **self.anim_args)


def override_animate(method):
Expand Down

0 comments on commit d2e570e

Please sign in to comment.