Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Get rid of NormalAnimationAsContinualAnimation

Grant Sanderson6c03bb4f1ead
diff --git a/manimlib/continual_animation/continual_animation.py b/manimlib/continual_animation/continual_animation.py
index f4837dc16..abca12da8 100644
--- a/manimlib/continual_animation/continual_animation.py
+++ b/manimlib/continual_animation/continual_animation.py
@@ -1,7 +1,6 @@
import copy
from manimlib.constants import *
-from manimlib.mobject.mobject import Group
from manimlib.mobject.mobject import Mobject
from manimlib.utils.config_ops import digest_config
@@ -52,19 +51,3 @@ class ContinualAnimation(object):
def copy(self):
return copy.deepcopy(self)
-
-
-class ContinualAnimationGroup(ContinualAnimation):
- CONFIG = {
- "start_up_time": 0,
- "wind_down_time": 0,
- }
-
- def __init__(self, *continual_animations, **kwargs):
- digest_config(self, kwargs, locals())
- self.group = Group(*[ca.mobject for ca in continual_animations])
- ContinualAnimation.__init__(self, self.group, **kwargs)
-
- def update_mobject(self, dt):
- for continual_animation in self.continual_animations:
- continual_animation.update(dt)
diff --git a/manimlib/continual_animation/from_animation.py b/manimlib/continual_animation/from_animation.py
index 2d478d25f..f48179166 100644
--- a/manimlib/continual_animation/from_animation.py
+++ b/manimlib/continual_animation/from_animation.py
@@ -1,22 +1,6 @@
from manimlib.continual_animation.continual_animation import ContinualAnimation
-class NormalAnimationAsContinualAnimation(ContinualAnimation):
- CONFIG = {
- "start_up_time": 0,
- "wind_down_time": 0,
- }
-
- def __init__(self, animation, **kwargs):
- self.animation = animation
- ContinualAnimation.__init__(self, animation.mobject, **kwargs)
-
- def update_mobject(self, dt):
- self.animation.update(
- min(float(self.internal_time) / self.animation.run_time, 1)
- )
-
-
class CycleAnimation(ContinualAnimation):
def __init__(self, animation, **kwargs):
self.animation = animation
diff --git a/manimlib/mobject/mobject_update_utils.py b/manimlib/mobject/mobject_update_utils.py
index 519cae339..f8407a214 100644
--- a/manimlib/mobject/mobject_update_utils.py
+++ b/manimlib/mobject/mobject_update_utils.py
@@ -1,4 +1,6 @@
import inspect
+import numpy as np
+
from manimlib.constants import DEGREES
from manimlib.constants import RIGHT
from manimlib.mobject.mobject import Mobject
@@ -30,3 +32,31 @@ def always_rotate(mobject, rate=20 * DEGREES, **kwargs):
lambda m, dt: m.rotate(dt * rate, **kwargs)
)
return mobject
+
+
+def turn_animation_into_updater(animation):
+ """
+ Note sure if this is actually useful. This is really
+ here just to replace past usage of
+ turn_animation_into_updater
+ """
+ mobject = animation.mobject
+ animation.suspend_mobject_updating = False
+ animation.begin()
+ animation.total_time = 0
+
+ def update(m, dt):
+ alpha = np.clip(
+ animation.total_time / animation.get_run_time(),
+ 0, 1,
+ )
+ if alpha >= 1:
+ animation.finish()
+ m.remove_updater(update)
+ else:
+ animation.interpolate(alpha)
+ animation.total_time += dt
+ animation.update_mobjects(dt)
+
+ mobject.add_updater(update)
+ return mobject
diff --git a/old_projects/alt_calc.py b/old_projects/alt_calc.py
index 13d4ec8b6..c636fef1f 100644
--- a/old_projects/alt_calc.py
+++ b/old_projects/alt_calc.py
@@ -781,9 +781,9 @@ class StartingCalc101(PiCreatureScene):
group.next_to(self.title, DOWN, MED_LARGE_BUFF)
group.rects = rects
group.continual_animations = [
- NormalAnimationAsContinualAnimation(Write(rects)),
- NormalAnimationAsContinualAnimation(ShowCreation(graph)),
- NormalAnimationAsContinualAnimation(FadeIn(gs.axes)),
+ turn_animation_into_updater(Write(rects)),
+ turn_animation_into_updater(ShowCreation(graph)),
+ turn_animation_into_updater(FadeIn(gs.axes)),
]
self.adjust_size(group)
return group
diff --git a/old_projects/fc1.py b/old_projects/fc1.py
index c64714b97..3cfb65384 100644
--- a/old_projects/fc1.py
+++ b/old_projects/fc1.py
@@ -15,7 +15,7 @@ class CrossingOneMillion(TeacherStudentsScene):
self.look_at(number, run_time=0)
confetti_spirils = self.confetti_spirils = list(map(
- NormalAnimationAsContinualAnimation,
+ turn_animation_into_updater,
get_confetti_animations(50)
))
self.add(*confetti_spirils)
diff --git a/old_projects/lost_lecture.py b/old_projects/lost_lecture.py
index de1ac3a51..a7f494dfe 100644
--- a/old_projects/lost_lecture.py
+++ b/old_projects/lost_lecture.py
@@ -1770,7 +1770,7 @@ class ProveEllipse(ShowEmergingEllipse, ShowEllipseDefiningProperty):
# Dot defining Q point
Q_dot = Dot(color=GREEN)
Q_dot.move_to(self.focal_sum_point)
- focal_sum_point_animation = NormalAnimationAsContinualAnimation(
+ focal_sum_point_animation = turn_animation_into_updater(
MaintainPositionRelativeTo(
self.focal_sum_point, Q_dot
)
@@ -1784,7 +1784,7 @@ class ProveEllipse(ShowEmergingEllipse, ShowEllipseDefiningProperty):
Q_label.match_color(Q_dot)
Q_label.add_to_back(Q_label.copy().set_stroke(BLACK, 5))
Q_label.next_to(Q_dot, UL, buff=0)
- Q_label_animation = NormalAnimationAsContinualAnimation(
+ Q_label_animation = turn_animation_into_updater(
MaintainPositionRelativeTo(Q_label, Q_dot)
)
diff --git a/old_projects/mug.py b/old_projects/mug.py
index 1120064c8..16704b76b 100644
--- a/old_projects/mug.py
+++ b/old_projects/mug.py
@@ -70,7 +70,7 @@ class HappyHolidays(TeacherStudentsScene):
run_time = 10,
rate_func = lambda x : x,
)
- return NormalAnimationAsContinualAnimation(snowflake_spirils)
+ return turn_animation_into_updater(snowflake_spirils)
class UtilitiesPuzzleScene(Scene):
CONFIG = {
diff --git a/old_projects/quaternions.py b/old_projects/quaternions.py
index 17a7ec2c4..848c83fae 100644
--- a/old_projects/quaternions.py
+++ b/old_projects/quaternions.py
@@ -1288,7 +1288,7 @@ class IntroduceLinusTheLinelander(Scene):
rate_func=there_and_back,
lag_ratio=0.1
)
- q_marks_continual = NormalAnimationAsContinualAnimation(q_marks_anim)
+ q_marks_continual = turn_animation_into_updater(q_marks_anim)
self.play(
FadeOut(to_fade),
diff --git a/old_projects/uncertainty.py b/old_projects/uncertainty.py
index 2405248d9..00c752b4d 100644
--- a/old_projects/uncertainty.py
+++ b/old_projects/uncertainty.py
@@ -1750,7 +1750,7 @@ class IntroduceDopplerRadar(Scene):
dish, randy,
speed = 0.97*speed, #Just needs slightly better alignment
)
- graph_draw = NormalAnimationAsContinualAnimation(
+ graph_draw = turn_animation_into_updater(
ShowCreation(
sum_graph,
rate_func=linear,
@@ -1824,7 +1824,7 @@ class IntroduceDopplerRadar(Scene):
echo_subtext.next_to(echo_text, RIGHT)
echo_subtext.match_color(echo_graph)
- graph_draw = NormalAnimationAsContinualAnimation(
+ graph_draw = turn_animation_into_updater(
ShowCreation(sum_graph, run_time = 8, rate_func=linear)
)
pulse = RadarPulse(dish, plane, n_pulse_singletons = 12)
diff --git a/old_projects/waves.py b/old_projects/waves.py
index b4b287f8d..c399ba462 100644
--- a/old_projects/waves.py
+++ b/old_projects/waves.py
@@ -4,6 +4,16 @@ from big_ol_pile_of_manim_imports import *
E_COLOR = BLUE
M_COLOR = YELLOW
+
+# Warning, much of what is below was implemented using
+# ConintualAnimation, which has now been deprecated. One
+# Should use Mobject updaters instead.
+#
+# That is, anything below implemented as a ContinualAnimation
+# should instead be a Mobject, where the update methods
+# should be added via Mobject.add_udpater.
+
+
class OscillatingVector(ContinualAnimation):
CONFIG = {
"tail" : ORIGIN,