@@ -178,7 +178,7 @@ def construct(self):
178
178
179
179
180
180
def turn_animation_into_updater (
181
- animation : Animation , cycle : bool = False , ** kwargs
181
+ animation : Animation , cycle : bool = False , delay : float = 0 , ** kwargs
182
182
) -> Mobject :
183
183
"""
184
184
Add an updater to the animation's mobject which applies
@@ -187,6 +187,8 @@ def turn_animation_into_updater(
187
187
If cycle is True, this repeats over and over. Otherwise,
188
188
the updater will be popped upon completion
189
189
190
+ The ``delay`` parameter is the delay (in seconds) before the animation starts..
191
+
190
192
Examples
191
193
--------
192
194
@@ -206,21 +208,22 @@ def construct(self):
206
208
mobject = animation .mobject
207
209
animation .suspend_mobject_updating = False
208
210
animation .begin ()
209
- animation .total_time = 0
211
+ animation .total_time = - delay
210
212
211
213
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 )
224
227
animation .total_time += dt
225
228
226
229
mobject .add_updater (update )
0 commit comments