Successions now correctly handle having zero animations

This commit is contained in:
Sridhar Ramesh
2018-02-01 16:29:28 -08:00
parent c0bd5f049f
commit 5c0e71a728

View File

@ -411,9 +411,6 @@ class Succession(Animation):
else:
run_time = sum(self.run_times)
self.num_anims = len(animations)
if self.num_anims == 0:
# TODO: Handle this; it should be easy enough, but requires some special cases below
print "Warning! Successions with zero animations are not currently handled!"
self.animations = animations
#Have to keep track of this run_time, because Scene.play
#might very well mess with it.
@ -422,7 +419,7 @@ class Succession(Animation):
# critical_alphas[i] is the start alpha of self.animations[i]
# critical_alphas[i + 1] is the end alpha of self.animations[i]
critical_times = np.concatenate(([0], np.cumsum(self.run_times)))
self.critical_alphas = map (lambda x : np.true_divide(x, run_time), critical_times)
self.critical_alphas = map (lambda x : np.true_divide(x, run_time), critical_times) if self.num_anims > 0 else [0.0]
# self.scene_mobjects_at_time[i] is the scene's mobjects at start of self.animations[i]
# self.scene_mobjects_at_time[i + 1] is the scene mobjects at end of self.animations[i]
@ -433,9 +430,12 @@ class Succession(Animation):
self.animations[i].clean_up(self.scene_mobjects_at_time[i + 1])
self.current_alpha = 0
self.current_anim_index = 0 #TODO: What if self.num_anims == 0?
self.mobject = self.scene_mobjects_at_time[0]
self.mobject.add(self.animations[0].mobject)
self.current_anim_index = 0 # If self.num_anims == 0, this is an invalid index, but so it goes
if self.num_anims > 0:
self.mobject = self.scene_mobjects_at_time[0]
self.mobject.add(self.animations[0].mobject)
else:
self.mobject = Group()
Animation.__init__(self, self.mobject, run_time = run_time, **kwargs)
@ -454,6 +454,9 @@ class Succession(Animation):
self.current_alpha = self.critical_alphas[index]
def update_mobject(self, alpha):
if self.num_anims == 0:
return
i = 0
while self.critical_alphas[i + 1] < alpha:
i = i + 1