mirror of
https://github.com/3b1b/manim.git
synced 2025-11-14 15:47:44 +00:00
Merge pull request #1862 from widcardw/dev
Add `set_anim_args` to `.animate` method
This commit is contained in:
commit
d2e570eb19
2 changed files with 33 additions and 4 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue