Get rid of NormalAnimationAsContinualAnimation

This commit is contained in:
Grant Sanderson
2019-02-11 14:08:48 -08:00
parent 1eb8180d3d
commit 6c03bb4f1e
10 changed files with 50 additions and 43 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)
)

View File

@ -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 = {

View File

@ -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),

View File

@ -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)

View File

@ -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,