Bug fixes to implementation of Succession animations

This commit is contained in:
Sridhar Ramesh
2018-01-19 13:02:41 -08:00
parent 2d34b2e28b
commit d74127bb7f
2 changed files with 24 additions and 18 deletions

View File

@ -329,7 +329,7 @@ class Succession(Animation):
"""
Each arg will either be an animation, or an animation class
followed by its arguments (and potentially a dict for
configuraiton).
configuration).
For example,
Succession(
@ -387,27 +387,27 @@ class Succession(Animation):
#might very well mess with it.
self.original_run_time = run_time
# 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)
mobject = Group(*[anim.mobject for anim in self.animations])
Animation.__init__(self, mobject, run_time = run_time, **kwargs)
def update_mobject(self, alpha):
if alpha >= 1.0:
self.animations[-1].update(1)
return
run_times = self.run_times
index = 0
time = alpha*self.original_run_time
while sum(run_times[:index+1]) < time:
index += 1
if index > self.last_index:
self.animations[self.last_index].update(1)
self.animations[self.last_index].clean_up()
self.last_index = index
curr_anim = self.animations[index]
sub_alpha = np.clip(
(time - sum(run_times[:index]))/run_times[index], 0, 1
)
curr_anim.update(sub_alpha)
for i in range(len(self.animations)):
sub_alpha = anti_interpolate(
self.critical_alphas[i],
self.critical_alphas[i + 1],
alpha
)
sub_alpha = clamp(0, 1, sub_alpha) # Could possibly adopt a non-clamping convention here
self.animations[i].update(sub_alpha)
def clean_up(self, *args, **kwargs):
for anim in self.animations:
anim.clean_up(*args, **kwargs)
class AnimationGroup(Animation):
CONFIG = {

View File

@ -304,6 +304,12 @@ def digest_locals(obj, keys = None):
def interpolate(start, end, alpha):
return (1-alpha)*start + alpha*end
def mid(start, end):
return (start + end)/2.0
def anti_interpolate(start, end, value):
return np.true_divide(value - start, end - start)
def clamp(lower, upper, val):
if val < lower:
return lower