Skip to content

Commit 263623e

Browse files
authored
Added a delay parameter to :func:.turn_animation_into_updater (#4039)
1 parent 73d2245 commit 263623e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

manim/animation/updaters/mobject_update_utils.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def construct(self):
178178

179179

180180
def turn_animation_into_updater(
181-
animation: Animation, cycle: bool = False, **kwargs
181+
animation: Animation, cycle: bool = False, delay: float = 0, **kwargs
182182
) -> Mobject:
183183
"""
184184
Add an updater to the animation's mobject which applies
@@ -187,6 +187,8 @@ def turn_animation_into_updater(
187187
If cycle is True, this repeats over and over. Otherwise,
188188
the updater will be popped upon completion
189189
190+
The ``delay`` parameter is the delay (in seconds) before the animation starts..
191+
190192
Examples
191193
--------
192194
@@ -206,21 +208,22 @@ def construct(self):
206208
mobject = animation.mobject
207209
animation.suspend_mobject_updating = False
208210
animation.begin()
209-
animation.total_time = 0
211+
animation.total_time = -delay
210212

211213
def update(m: Mobject, dt: float):
212-
run_time = animation.get_run_time()
213-
time_ratio = animation.total_time / run_time
214-
if cycle:
215-
alpha = time_ratio % 1
216-
else:
217-
alpha = np.clip(time_ratio, 0, 1)
218-
if alpha >= 1:
219-
animation.finish()
220-
m.remove_updater(update)
221-
return
222-
animation.interpolate(alpha)
223-
animation.update_mobjects(dt)
214+
if animation.total_time >= 0:
215+
run_time = animation.get_run_time()
216+
time_ratio = animation.total_time / run_time
217+
if cycle:
218+
alpha = time_ratio % 1
219+
else:
220+
alpha = np.clip(time_ratio, 0, 1)
221+
if alpha >= 1:
222+
animation.finish()
223+
m.remove_updater(update)
224+
return
225+
animation.interpolate(alpha)
226+
animation.update_mobjects(dt)
224227
animation.total_time += dt
225228

226229
mobject.add_updater(update)

0 commit comments

Comments
 (0)