Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Bug fixes to implementation of Succession animations

Sridhar Rameshd74127bb7fb2
diff --git a/animation/simple_animations.py b/animation/simple_animations.py
index bac8ffcc0..68e4176e4 100644
--- a/animation/simple_animations.py
+++ b/animation/simple_animations.py
@@ -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 = {
diff --git a/helpers.py b/helpers.py
index 87a04a463..57db6db01 100644
--- a/helpers.py
+++ b/helpers.py
@@ -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