Skip to content

Commit

Permalink
Add a delay parameter to turn_animation_into_updater
Browse files Browse the repository at this point in the history
Add a `delay` parameter to the `turn_animation_into_updater` function to allow for more precise control over when the animation starts. This parameter allows us to perform more complex timeline control.
  • Loading branch information
ChungLeeCN authored Dec 3, 2024
1 parent 73d2245 commit 4c57da7
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions manim/animation/updaters/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def construct(self):


def turn_animation_into_updater(
animation: Animation, cycle: bool = False, **kwargs
animation: Animation, cycle: bool = False, delay: float = 0, **kwargs
) -> Mobject:
"""
Add an updater to the animation's mobject which applies
Expand All @@ -187,6 +187,8 @@ def turn_animation_into_updater(
If cycle is True, this repeats over and over. Otherwise,
the updater will be popped upon completion
The `delay` parameter allows us to perform more complex timeline control.
Examples
--------
Expand All @@ -206,21 +208,22 @@ def construct(self):
mobject = animation.mobject
animation.suspend_mobject_updating = False
animation.begin()
animation.total_time = 0
animation.total_time = -delay

def update(m: Mobject, dt: float):
run_time = animation.get_run_time()
time_ratio = animation.total_time / run_time
if cycle:
alpha = time_ratio % 1
else:
alpha = np.clip(time_ratio, 0, 1)
if alpha >= 1:
animation.finish()
m.remove_updater(update)
return
animation.interpolate(alpha)
animation.update_mobjects(dt)
if animation.total_time >= 0:
run_time = animation.get_run_time()
time_ratio = animation.total_time / run_time
if cycle:
alpha = time_ratio % 1
else:
alpha = np.clip(time_ratio, 0, 1)
if alpha >= 1:
animation.finish()
m.remove_updater(update)
return
animation.interpolate(alpha)
animation.update_mobjects(dt)
animation.total_time += dt

mobject.add_updater(update)
Expand Down

0 comments on commit 4c57da7

Please sign in to comment.