mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Bug fixes to implementation of Succession animations
This commit is contained in:
parent
2d34b2e28b
commit
d74127bb7f
2 changed files with 24 additions and 18 deletions
|
@ -329,7 +329,7 @@ class Succession(Animation):
|
||||||
"""
|
"""
|
||||||
Each arg will either be an animation, or an animation class
|
Each arg will either be an animation, or an animation class
|
||||||
followed by its arguments (and potentially a dict for
|
followed by its arguments (and potentially a dict for
|
||||||
configuraiton).
|
configuration).
|
||||||
|
|
||||||
For example,
|
For example,
|
||||||
Succession(
|
Succession(
|
||||||
|
@ -387,27 +387,27 @@ class Succession(Animation):
|
||||||
#might very well mess with it.
|
#might very well mess with it.
|
||||||
self.original_run_time = run_time
|
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])
|
mobject = Group(*[anim.mobject for anim in self.animations])
|
||||||
Animation.__init__(self, mobject, run_time = run_time, **kwargs)
|
Animation.__init__(self, mobject, run_time = run_time, **kwargs)
|
||||||
|
|
||||||
def update_mobject(self, alpha):
|
def update_mobject(self, alpha):
|
||||||
if alpha >= 1.0:
|
for i in range(len(self.animations)):
|
||||||
self.animations[-1].update(1)
|
sub_alpha = anti_interpolate(
|
||||||
return
|
self.critical_alphas[i],
|
||||||
run_times = self.run_times
|
self.critical_alphas[i + 1],
|
||||||
index = 0
|
alpha
|
||||||
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)
|
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):
|
class AnimationGroup(Animation):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
|
|
@ -304,6 +304,12 @@ def digest_locals(obj, keys = None):
|
||||||
def interpolate(start, end, alpha):
|
def interpolate(start, end, alpha):
|
||||||
return (1-alpha)*start + alpha*end
|
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):
|
def clamp(lower, upper, val):
|
||||||
if val < lower:
|
if val < lower:
|
||||||
return lower
|
return lower
|
||||||
|
|
Loading…
Add table
Reference in a new issue