Better behavior for turn_animation_into_updater and cycle_animations

This commit is contained in:
Grant Sanderson 2019-04-02 17:43:18 -07:00
parent 043e3986f6
commit db6958462f

View file

@ -77,16 +77,15 @@ def turn_animation_into_updater(animation, cycle=False, **kwargs):
def update(m, dt): def update(m, dt):
run_time = animation.get_run_time() run_time = animation.get_run_time()
alpha = np.clip( time_ratio = animation.total_time / run_time
animation.total_time / run_time,
0, 1,
)
if cycle: if cycle:
animation.total_time = animation.total_time % run_time alpha = time_ratio % 1
elif alpha >= 1: else:
animation.finish() alpha = np.clip(time_ratio, 0, 1)
m.remove_updater(update) if alpha >= 1:
return animation.finish()
m.remove_updater(update)
return
animation.interpolate(alpha) animation.interpolate(alpha)
animation.update_mobjects(dt) animation.update_mobjects(dt)
animation.total_time += dt animation.total_time += dt