mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 13:34:19 +08:00
Get rid of NormalAnimationAsContinualAnimation
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.mobject import Group
|
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
|
|
||||||
@ -52,19 +51,3 @@ class ContinualAnimation(object):
|
|||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return copy.deepcopy(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)
|
|
||||||
|
@ -1,22 +1,6 @@
|
|||||||
from manimlib.continual_animation.continual_animation import ContinualAnimation
|
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):
|
class CycleAnimation(ContinualAnimation):
|
||||||
def __init__(self, animation, **kwargs):
|
def __init__(self, animation, **kwargs):
|
||||||
self.animation = animation
|
self.animation = animation
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import inspect
|
import inspect
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from manimlib.constants import DEGREES
|
from manimlib.constants import DEGREES
|
||||||
from manimlib.constants import RIGHT
|
from manimlib.constants import RIGHT
|
||||||
from manimlib.mobject.mobject import Mobject
|
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)
|
lambda m, dt: m.rotate(dt * rate, **kwargs)
|
||||||
)
|
)
|
||||||
return mobject
|
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
|
||||||
|
@ -781,9 +781,9 @@ class StartingCalc101(PiCreatureScene):
|
|||||||
group.next_to(self.title, DOWN, MED_LARGE_BUFF)
|
group.next_to(self.title, DOWN, MED_LARGE_BUFF)
|
||||||
group.rects = rects
|
group.rects = rects
|
||||||
group.continual_animations = [
|
group.continual_animations = [
|
||||||
NormalAnimationAsContinualAnimation(Write(rects)),
|
turn_animation_into_updater(Write(rects)),
|
||||||
NormalAnimationAsContinualAnimation(ShowCreation(graph)),
|
turn_animation_into_updater(ShowCreation(graph)),
|
||||||
NormalAnimationAsContinualAnimation(FadeIn(gs.axes)),
|
turn_animation_into_updater(FadeIn(gs.axes)),
|
||||||
]
|
]
|
||||||
self.adjust_size(group)
|
self.adjust_size(group)
|
||||||
return group
|
return group
|
||||||
|
@ -15,7 +15,7 @@ class CrossingOneMillion(TeacherStudentsScene):
|
|||||||
self.look_at(number, run_time=0)
|
self.look_at(number, run_time=0)
|
||||||
|
|
||||||
confetti_spirils = self.confetti_spirils = list(map(
|
confetti_spirils = self.confetti_spirils = list(map(
|
||||||
NormalAnimationAsContinualAnimation,
|
turn_animation_into_updater,
|
||||||
get_confetti_animations(50)
|
get_confetti_animations(50)
|
||||||
))
|
))
|
||||||
self.add(*confetti_spirils)
|
self.add(*confetti_spirils)
|
||||||
|
@ -1770,7 +1770,7 @@ class ProveEllipse(ShowEmergingEllipse, ShowEllipseDefiningProperty):
|
|||||||
# Dot defining Q point
|
# Dot defining Q point
|
||||||
Q_dot = Dot(color=GREEN)
|
Q_dot = Dot(color=GREEN)
|
||||||
Q_dot.move_to(self.focal_sum_point)
|
Q_dot.move_to(self.focal_sum_point)
|
||||||
focal_sum_point_animation = NormalAnimationAsContinualAnimation(
|
focal_sum_point_animation = turn_animation_into_updater(
|
||||||
MaintainPositionRelativeTo(
|
MaintainPositionRelativeTo(
|
||||||
self.focal_sum_point, Q_dot
|
self.focal_sum_point, Q_dot
|
||||||
)
|
)
|
||||||
@ -1784,7 +1784,7 @@ class ProveEllipse(ShowEmergingEllipse, ShowEllipseDefiningProperty):
|
|||||||
Q_label.match_color(Q_dot)
|
Q_label.match_color(Q_dot)
|
||||||
Q_label.add_to_back(Q_label.copy().set_stroke(BLACK, 5))
|
Q_label.add_to_back(Q_label.copy().set_stroke(BLACK, 5))
|
||||||
Q_label.next_to(Q_dot, UL, buff=0)
|
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)
|
MaintainPositionRelativeTo(Q_label, Q_dot)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class HappyHolidays(TeacherStudentsScene):
|
|||||||
run_time = 10,
|
run_time = 10,
|
||||||
rate_func = lambda x : x,
|
rate_func = lambda x : x,
|
||||||
)
|
)
|
||||||
return NormalAnimationAsContinualAnimation(snowflake_spirils)
|
return turn_animation_into_updater(snowflake_spirils)
|
||||||
|
|
||||||
class UtilitiesPuzzleScene(Scene):
|
class UtilitiesPuzzleScene(Scene):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
@ -1288,7 +1288,7 @@ class IntroduceLinusTheLinelander(Scene):
|
|||||||
rate_func=there_and_back,
|
rate_func=there_and_back,
|
||||||
lag_ratio=0.1
|
lag_ratio=0.1
|
||||||
)
|
)
|
||||||
q_marks_continual = NormalAnimationAsContinualAnimation(q_marks_anim)
|
q_marks_continual = turn_animation_into_updater(q_marks_anim)
|
||||||
|
|
||||||
self.play(
|
self.play(
|
||||||
FadeOut(to_fade),
|
FadeOut(to_fade),
|
||||||
|
@ -1750,7 +1750,7 @@ class IntroduceDopplerRadar(Scene):
|
|||||||
dish, randy,
|
dish, randy,
|
||||||
speed = 0.97*speed, #Just needs slightly better alignment
|
speed = 0.97*speed, #Just needs slightly better alignment
|
||||||
)
|
)
|
||||||
graph_draw = NormalAnimationAsContinualAnimation(
|
graph_draw = turn_animation_into_updater(
|
||||||
ShowCreation(
|
ShowCreation(
|
||||||
sum_graph,
|
sum_graph,
|
||||||
rate_func=linear,
|
rate_func=linear,
|
||||||
@ -1824,7 +1824,7 @@ class IntroduceDopplerRadar(Scene):
|
|||||||
echo_subtext.next_to(echo_text, RIGHT)
|
echo_subtext.next_to(echo_text, RIGHT)
|
||||||
echo_subtext.match_color(echo_graph)
|
echo_subtext.match_color(echo_graph)
|
||||||
|
|
||||||
graph_draw = NormalAnimationAsContinualAnimation(
|
graph_draw = turn_animation_into_updater(
|
||||||
ShowCreation(sum_graph, run_time = 8, rate_func=linear)
|
ShowCreation(sum_graph, run_time = 8, rate_func=linear)
|
||||||
)
|
)
|
||||||
pulse = RadarPulse(dish, plane, n_pulse_singletons = 12)
|
pulse = RadarPulse(dish, plane, n_pulse_singletons = 12)
|
||||||
|
@ -4,6 +4,16 @@ from big_ol_pile_of_manim_imports import *
|
|||||||
E_COLOR = BLUE
|
E_COLOR = BLUE
|
||||||
M_COLOR = YELLOW
|
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):
|
class OscillatingVector(ContinualAnimation):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"tail" : ORIGIN,
|
"tail" : ORIGIN,
|
||||||
|
Reference in New Issue
Block a user