mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 14:03:59 +08:00
Remove CycleAnimation ContinualAnimation, replace with cycle_animation which adds a mobject updater
This commit is contained in:
@ -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)
|
|
@ -1,9 +1,9 @@
|
|||||||
from manimlib.animation.numbers import ChangingDecimal
|
# from manimlib.animation.numbers import ChangingDecimal
|
||||||
from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation
|
# from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation
|
||||||
|
|
||||||
|
|
||||||
class ContinualChangingDecimal(NormalAnimationAsContinualAnimation):
|
# class ContinualChangingDecimal(NormalAnimationAsContinualAnimation):
|
||||||
def __init__(self, *args, **kwargs):
|
# def __init__(self, *args, **kwargs):
|
||||||
NormalAnimationAsContinualAnimation.__init__(
|
# NormalAnimationAsContinualAnimation.__init__(
|
||||||
self, ChangingDecimal(*args, **kwargs)
|
# self, ChangingDecimal(*args, **kwargs)
|
||||||
)
|
# )
|
||||||
|
@ -34,29 +34,41 @@ def always_rotate(mobject, rate=20 * DEGREES, **kwargs):
|
|||||||
return mobject
|
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
|
Add an updater to the animation's mobject which applies
|
||||||
here just to replace past usage of
|
the interpolation and update functions of the animation
|
||||||
turn_animation_into_updater
|
|
||||||
|
If cycle is True, this repeats over and over. Otherwise,
|
||||||
|
the updater will be popped uplon completion
|
||||||
"""
|
"""
|
||||||
mobject = animation.mobject
|
mobject = animation.mobject
|
||||||
|
animation.update_config(**kwargs)
|
||||||
animation.suspend_mobject_updating = False
|
animation.suspend_mobject_updating = False
|
||||||
animation.begin()
|
animation.begin()
|
||||||
animation.total_time = 0
|
animation.total_time = 0
|
||||||
|
|
||||||
def update(m, dt):
|
def update(m, dt):
|
||||||
|
run_time = animation.get_run_time()
|
||||||
alpha = np.clip(
|
alpha = np.clip(
|
||||||
animation.total_time / animation.get_run_time(),
|
animation.total_time / run_time,
|
||||||
0, 1,
|
0, 1,
|
||||||
)
|
)
|
||||||
if alpha >= 1:
|
if cycle:
|
||||||
|
animation.total_time = animation.total_time % run_time
|
||||||
|
elif alpha >= 1:
|
||||||
animation.finish()
|
animation.finish()
|
||||||
m.remove_updater(update)
|
m.remove_updater(update)
|
||||||
else:
|
return
|
||||||
animation.interpolate(alpha)
|
animation.interpolate(alpha)
|
||||||
animation.total_time += dt
|
animation.update_mobjects(dt)
|
||||||
animation.update_mobjects(dt)
|
animation.total_time += dt
|
||||||
|
|
||||||
mobject.add_updater(update)
|
mobject.add_updater(update)
|
||||||
return mobject
|
return mobject
|
||||||
|
|
||||||
|
|
||||||
|
def cycle_animation(animation, **kwargs):
|
||||||
|
return turn_animation_into_updater(
|
||||||
|
animation, cycle=True, **kwargs
|
||||||
|
)
|
||||||
|
@ -2259,7 +2259,7 @@ class GraphOnePlusOneOverX(GraphScene):
|
|||||||
lag_ratio=0.5,
|
lag_ratio=0.5,
|
||||||
run_time=2
|
run_time=2
|
||||||
)
|
)
|
||||||
line.continual_anim = CycleAnimation(line_anim)
|
cycle_animation(line_anim)
|
||||||
lines.add(line)
|
lines.add(line)
|
||||||
|
|
||||||
phi_line, phi_bro_line = lines
|
phi_line, phi_bro_line = lines
|
||||||
|
@ -634,7 +634,7 @@ class EccentricityInThumbtackCase(ShowArrayOfEccentricities):
|
|||||||
|
|
||||||
def get_ellipse_point_update(self, ellipse):
|
def get_ellipse_point_update(self, ellipse):
|
||||||
dot = Dot(color=RED)
|
dot = Dot(color=RED)
|
||||||
return CycleAnimation(MoveAlongPath(
|
return cycle_animation(MoveAlongPath(
|
||||||
dot, ellipse,
|
dot, ellipse,
|
||||||
run_time=5,
|
run_time=5,
|
||||||
rate_func=linear
|
rate_func=linear
|
||||||
@ -1584,7 +1584,7 @@ class EllipseLengthsLinedUp(EccentricityInThumbtackCase):
|
|||||||
foci = self.get_foci(ellipse)
|
foci = self.get_foci(ellipse)
|
||||||
|
|
||||||
point = VectorizedPoint()
|
point = VectorizedPoint()
|
||||||
point_movement = CycleAnimation(
|
point_movement = cycle_animation(
|
||||||
MoveAlongPath(
|
MoveAlongPath(
|
||||||
point, ellipse,
|
point, ellipse,
|
||||||
run_time=5,
|
run_time=5,
|
||||||
|
Reference in New Issue
Block a user