Merge pull request #1862 from widcardw/dev

Add `set_anim_args` to `.animate` method
This commit is contained in:
Grant Sanderson 2022-09-13 12:42:36 -07:00 committed by GitHub
commit d2e570eb19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 4 deletions

View file

@ -176,9 +176,9 @@ class MoveToTarget(Transform):
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):

View file

@ -2015,7 +2015,9 @@ class _AnimationBuilder:
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)
@ -2040,13 +2042,40 @@ class _AnimationBuilder:
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):