From 605ca08e6f223fcde8fe68aa2ea14e527716bb56 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 11 Feb 2019 14:28:45 -0800 Subject: [PATCH] Remove CycleAnimation ContinualAnimation, replace with cycle_animation which adds a mobject updater --- .../continual_animation/from_animation.py | 12 ------- manimlib/continual_animation/numbers.py | 14 ++++---- manimlib/mobject/mobject_update_utils.py | 32 +++++++++++++------ old_projects/alt_calc.py | 2 +- old_projects/dandelin.py | 4 +-- 5 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 manimlib/continual_animation/from_animation.py diff --git a/manimlib/continual_animation/from_animation.py b/manimlib/continual_animation/from_animation.py deleted file mode 100644 index f4817916..00000000 --- a/manimlib/continual_animation/from_animation.py +++ /dev/null @@ -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) diff --git a/manimlib/continual_animation/numbers.py b/manimlib/continual_animation/numbers.py index f8763ec6..a08396f8 100644 --- a/manimlib/continual_animation/numbers.py +++ b/manimlib/continual_animation/numbers.py @@ -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) +# ) diff --git a/manimlib/mobject/mobject_update_utils.py b/manimlib/mobject/mobject_update_utils.py index f8407a21..5fc0ce17 100644 --- a/manimlib/mobject/mobject_update_utils.py +++ b/manimlib/mobject/mobject_update_utils.py @@ -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: - animation.interpolate(alpha) - animation.total_time += dt - animation.update_mobjects(dt) + return + animation.interpolate(alpha) + 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 + ) diff --git a/old_projects/alt_calc.py b/old_projects/alt_calc.py index c636fef1..5bb80b87 100644 --- a/old_projects/alt_calc.py +++ b/old_projects/alt_calc.py @@ -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 diff --git a/old_projects/dandelin.py b/old_projects/dandelin.py index 0bf1e398..496fda95 100644 --- a/old_projects/dandelin.py +++ b/old_projects/dandelin.py @@ -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,