Remove CycleAnimation ContinualAnimation, replace with cycle_animation which adds a mobject updater

This commit is contained in:
Grant Sanderson
2019-02-11 14:28:45 -08:00
parent 6c03bb4f1e
commit 605ca08e6f
5 changed files with 32 additions and 32 deletions

View File

@ -1,12 +0,0 @@
from manimlib.continual_animation.continual_animation import ContinualAnimation
class CycleAnimation(ContinualAnimation):
def __init__(self, animation, **kwargs):
self.animation = animation
ContinualAnimation.__init__(self, animation.mobject, **kwargs)
def update_mobject(self, dt):
mod_value = self.internal_time % self.animation.run_time
alpha = mod_value / float(self.animation.run_time)
self.animation.update(alpha)

View File

@ -1,9 +1,9 @@
from manimlib.animation.numbers import ChangingDecimal
from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation
# from manimlib.animation.numbers import ChangingDecimal
# from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation
class ContinualChangingDecimal(NormalAnimationAsContinualAnimation):
def __init__(self, *args, **kwargs):
NormalAnimationAsContinualAnimation.__init__(
self, ChangingDecimal(*args, **kwargs)
)
# class ContinualChangingDecimal(NormalAnimationAsContinualAnimation):
# def __init__(self, *args, **kwargs):
# NormalAnimationAsContinualAnimation.__init__(
# self, ChangingDecimal(*args, **kwargs)
# )

View File

@ -34,29 +34,41 @@ def always_rotate(mobject, rate=20 * DEGREES, **kwargs):
return mobject
def turn_animation_into_updater(animation):
def turn_animation_into_updater(animation, cycle=False, **kwargs):
"""
Note sure if this is actually useful. This is really
here just to replace past usage of
turn_animation_into_updater
Add an updater to the animation's mobject which applies
the interpolation and update functions of the animation
If cycle is True, this repeats over and over. Otherwise,
the updater will be popped uplon completion
"""
mobject = animation.mobject
animation.update_config(**kwargs)
animation.suspend_mobject_updating = False
animation.begin()
animation.total_time = 0
def update(m, dt):
run_time = animation.get_run_time()
alpha = np.clip(
animation.total_time / animation.get_run_time(),
animation.total_time / run_time,
0, 1,
)
if alpha >= 1:
if cycle:
animation.total_time = animation.total_time % run_time
elif alpha >= 1:
animation.finish()
m.remove_updater(update)
else:
return
animation.interpolate(alpha)
animation.total_time += dt
animation.update_mobjects(dt)
animation.total_time += dt
mobject.add_updater(update)
return mobject
def cycle_animation(animation, **kwargs):
return turn_animation_into_updater(
animation, cycle=True, **kwargs
)

View File

@ -2259,7 +2259,7 @@ class GraphOnePlusOneOverX(GraphScene):
lag_ratio=0.5,
run_time=2
)
line.continual_anim = CycleAnimation(line_anim)
cycle_animation(line_anim)
lines.add(line)
phi_line, phi_bro_line = lines

View File

@ -634,7 +634,7 @@ class EccentricityInThumbtackCase(ShowArrayOfEccentricities):
def get_ellipse_point_update(self, ellipse):
dot = Dot(color=RED)
return CycleAnimation(MoveAlongPath(
return cycle_animation(MoveAlongPath(
dot, ellipse,
run_time=5,
rate_func=linear
@ -1584,7 +1584,7 @@ class EllipseLengthsLinedUp(EccentricityInThumbtackCase):
foci = self.get_foci(ellipse)
point = VectorizedPoint()
point_movement = CycleAnimation(
point_movement = cycle_animation(
MoveAlongPath(
point, ellipse,
run_time=5,