Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Removed ContinualAnimation, reimplemented some of its occurances in the old_projects, added warnings for the rest

Grant Sandersonb2c7e83843f5
diff --git a/manimlib/continual_animation/continual_animation.py b/manimlib/continual_animation/continual_animation.py
deleted file mode 100644
index abca12da8..000000000
--- a/manimlib/continual_animation/continual_animation.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import copy
-
-from manimlib.constants import *
-from manimlib.mobject.mobject import Mobject
-from manimlib.utils.config_ops import digest_config
-
-
-class ContinualAnimation(object):
- CONFIG = {
- "start_up_time": 1,
- "wind_down_time": 1,
- "end_time": np.inf,
- }
-
- def __init__(self, mobject, **kwargs):
- assert(isinstance(mobject, Mobject))
- digest_config(self, kwargs, locals())
- self.internal_time = 0
- self.external_time = 0
- self.setup()
- self.update(0)
-
- def setup(self):
- # To implement in subclass
- pass
-
- def begin_wind_down(self, wind_down_time=None):
- if wind_down_time is not None:
- self.wind_down_time = wind_down_time
- self.end_time = self.external_time + self.wind_down_time
-
- def update(self, dt):
- # TODO, currenty time moves slower for a
- # continual animation during its start up
- # to help smooth things out. Does this have
- # unwanted consequences?
- self.external_time += dt
- if self.external_time < self.start_up_time:
- dt *= float(self.external_time) / self.start_up_time
- elif self.external_time > self.end_time - self.wind_down_time:
- dt *= np.clip(
- float(self.end_time - self.external_time) / self.wind_down_time,
- 0, 1
- )
- self.internal_time += dt
- self.update_mobject(dt)
-
- def update_mobject(self, dt):
- # To implement in subclass
- pass
-
- def copy(self):
- return copy.deepcopy(self)
diff --git a/manimlib/once_useful_constructs/light.py b/manimlib/once_useful_constructs/light.py
index 048829342..6bf519191 100644
--- a/manimlib/once_useful_constructs/light.py
+++ b/manimlib/once_useful_constructs/light.py
@@ -7,10 +7,8 @@ from manimlib.animation.fading import FadeIn
from manimlib.animation.fading import FadeOut
from manimlib.animation.transform import Transform
from manimlib.constants import *
-from manimlib.continual_animation.continual_animation import ContinualAnimation
from manimlib.mobject.geometry import AnnularSector
from manimlib.mobject.geometry import Annulus
-from manimlib.mobject.mobject import Mobject
from manimlib.mobject.svg.svg_mobject import SVGMobject
from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.mobject.types.vectorized_mobject import VectorizedPoint
@@ -70,8 +68,7 @@ class SwitchOff(LaggedStartMap):
raise Exception(
"Only AmbientLights and Spotlights can be switched off")
light.submobjects = light.submobjects[::-1]
- LaggedStartMap.__init__(self,
- FadeOut, light, **kwargs)
+ LaggedStartMap.__init__(self, FadeOut, light, **kwargs)
light.submobjects = light.submobjects[::-1]
@@ -596,11 +593,8 @@ class LightSource(VMobject):
self.shadow.mark_paths_closed = True
-class ScreenTracker(ContinualAnimation):
- def __init__(self, light_source, **kwargs):
- self.light_source = light_source
- dummy_mob = Mobject()
- ContinualAnimation.__init__(self, dummy_mob, **kwargs)
-
- def update_mobject(self, dt):
- self.light_source.update()
+# Redefining what was once a ContinualAnimation class
+# as a function
+def ScreenTracker(light_source):
+ light_source.add_updater(lambda m: m.update())
+ return light_source
diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py
index ce2ef4f21..6776da626 100644
--- a/manimlib/scene/scene.py
+++ b/manimlib/scene/scene.py
@@ -11,7 +11,6 @@ from manimlib.animation.transform import MoveToTarget, ApplyMethod
from manimlib.camera.camera import Camera
from manimlib.constants import *
from manimlib.container.container import Container
-from manimlib.continual_animation.continual_animation import ContinualAnimation
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.svg.tex_mobject import TextMobject
from manimlib.scene.scene_file_writer import SceneFileWriter
diff --git a/old_projects/WindingNumber.py b/old_projects/WindingNumber.py
index 7d24d1231..feaf0fc73 100644
--- a/old_projects/WindingNumber.py
+++ b/old_projects/WindingNumber.py
@@ -1,5 +1,12 @@
from big_ol_pile_of_manim_imports import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
import time
import mpmath
diff --git a/old_projects/basel/basel.py b/old_projects/basel/basel.py
index 62fb9d591..98b061a9c 100644
--- a/old_projects/basel/basel.py
+++ b/old_projects/basel/basel.py
@@ -5,6 +5,13 @@ from big_ol_pile_of_manim_imports import *
from once_useful_constructs.light import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
import types
import functools
diff --git a/old_projects/basel/basel2.py b/old_projects/basel/basel2.py
index 50b6c9b74..c90b320f0 100644
--- a/old_projects/basel/basel2.py
+++ b/old_projects/basel/basel2.py
@@ -5,6 +5,14 @@
from big_ol_pile_of_manim_imports import *
from once_useful_constructs.light import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
+
import types
import functools
diff --git a/old_projects/clacks/question.py b/old_projects/clacks/question.py
index cf6ff9384..43106bb8c 100644
--- a/old_projects/clacks/question.py
+++ b/old_projects/clacks/question.py
@@ -197,7 +197,9 @@ class SlidingBlocks(VGroup):
return clack_data
-class ClackFlashes(ContinualAnimation):
+# TODO, this is untested after turning it from a
+# ContinualAnimation into a VGroup
+class ClackFlashes(VGroup):
CONFIG = {
"flash_config": {
"run_time": 0.5,
@@ -209,9 +211,8 @@ class ClackFlashes(ContinualAnimation):
}
def __init__(self, clack_data, **kwargs):
- digest_config(self, kwargs)
+ VGroup.__init__(self, **kwargs)
self.flashes = []
- group = Group()
last_time = 0
for location, time in clack_data:
if (time - last_time) < self.min_time_between_flashes:
@@ -225,24 +226,23 @@ class ClackFlashes(ContinualAnimation):
flash.start_time = time
flash.end_time = time + flash.run_time
self.flashes.append(flash)
- ContinualAnimation.__init__(self, group, **kwargs)
- def update_mobject(self, dt):
- total_time = self.get_time()
- group = self.mobject
+ self.time = 0
+ self.add_updater(lambda m: m.update(dt))
+
+ def update(self, dt):
+ time = self.time
+ self.time += dt
for flash in self.flashes:
- if flash.start_time < total_time < flash.end_time:
- if flash.mobject not in group:
- group.add(flash.mobject)
+ if flash.start_time < time < flash.end_time:
+ if flash.mobject not in self.submobjects:
+ self.add(flash.mobject)
flash.update(
- (total_time - flash.start_time) / flash.run_time
+ (time - flash.start_time) / flash.run_time
)
else:
- if flash.mobject in group:
- group.remove(flash.mobject)
-
- def get_time(self):
- return self.external_time
+ if flash.mobject in self.submobjects:
+ self.remove(flash.mobject)
class Wall(Line):
diff --git a/old_projects/div_curl.py b/old_projects/div_curl.py
index cbc0c3f02..ebb0cb057 100644
--- a/old_projects/div_curl.py
+++ b/old_projects/div_curl.py
@@ -5,7 +5,7 @@ DEFAULT_SCALAR_FIELD_COLORS = [BLUE_E, GREEN, YELLOW, RED]
# Quick note to anyone coming to this file with the
# intent of recreating animations from the video. Some
-# of these, especially those involving StreamLineAnimation,
+# of these, especially those involving AnimatedStreamLines,
# can take an extremely long time to run, but much of the
# computational cost is just for giving subtle little effects
# which don't matter too much. Switching the line_anim_class
@@ -349,41 +349,39 @@ class VectorField(VGroup):
return vect
-# Continual animations
-
-
-class VectorFieldFlow(ContinualAnimation):
- CONFIG = {
- "mode": None,
- }
-
- def __init__(self, mobject, func, **kwargs):
- """
- Func should take in a vector in R3, and output a vector in R3
- """
- self.func = func
- ContinualAnimation.__init__(self, mobject, **kwargs)
-
- def update_mobject(self, dt):
- self.apply_nudge(dt)
-
- def apply_nudge(self, dt):
- self.mobject.shift(self.func(self.mobject.get_center()) * dt)
+# Redefining what was once a ContinualAnimation class
+# as a function
+def VectorFieldFlow(mobject, func):
+ mobject.add_updater(
+ lambda m, dt: m.shift(
+ func(m.get_center()) * dt
+ )
+ )
+ return mobject
-class VectorFieldSubmobjectFlow(VectorFieldFlow):
- def apply_nudge(self, dt):
- for submob in self.mobject:
+# Redefining what was once a ContinualAnimation class
+# as a function
+def VectorFieldSubmobjectFlow(mobject, func):
+ def apply_nudge(mob, dt):
+ for submob in mob:
x, y = submob.get_center()[:2]
if abs(x) < FRAME_WIDTH and abs(y) < FRAME_HEIGHT:
- submob.shift(self.func(submob.get_center()) * dt)
+ submob.shift(func(submob.get_center()) * dt)
+
+ mobject.add_updater(apply_nudge)
+ return mobject
-class VectorFieldPointFlow(VectorFieldFlow):
+# Redefining what was once a ContinualAnimation class
+# as a function
+def VectorFieldPointFlow(mobject, func):
def apply_nudge(self, dt):
self.mobject.apply_function(
- lambda p: p + self.func(p) * dt
+ lambda p: p + func(p) * dt
)
+ mobject.add_updater(apply_nudge)
+ return mobject
# TODO: Make it so that you can have a group of stream_lines
@@ -413,7 +411,9 @@ class ShowPassingFlashWithThinningStrokeWidth(AnimationGroup):
])
-class StreamLineAnimation(ContinualAnimation):
+# TODO, this is untested after turning it from a
+# ContinualAnimation into a VGroup
+class AnimatedStreamLines(VGroup):
CONFIG = {
"lag_range": 4,
"line_anim_class": ShowPassingFlash,
@@ -425,16 +425,16 @@ class StreamLineAnimation(ContinualAnimation):
}
def __init__(self, stream_lines, **kwargs):
- digest_config(self, kwargs)
+ VGroup.__init__(self, **kwargs)
self.stream_lines = stream_lines
- group = VGroup()
for line in stream_lines:
line.anim = self.line_anim_class(line, **self.line_anim_config)
line.time = -self.lag_range * random.random()
- group.add(line.anim.mobject)
- ContinualAnimation.__init__(self, group, **kwargs)
+ self.add(line.anim.mobject)
- def update_mobject(self, dt):
+ self.add_updater(lambda m, dt: m.update(dt))
+
+ def update(self, dt):
stream_lines = self.stream_lines
for line in stream_lines:
line.time += dt
@@ -442,22 +442,26 @@ class StreamLineAnimation(ContinualAnimation):
line.anim.update(adjusted_time / line.anim.run_time)
-class JigglingSubmobjects(ContinualAnimation):
+# TODO, this is untested after turning it from a
+# ContinualAnimation into a VGroup
+class JigglingSubmobjects(VGroup):
CONFIG = {
"amplitude": 0.05,
"jiggles_per_second": 1,
}
def __init__(self, group, **kwargs):
+ VGroup.__init__(self, **kwargs)
for submob in group.submobjects:
submob.jiggling_direction = rotate_vector(
RIGHT, np.random.random() * TAU,
)
submob.jiggling_phase = np.random.random() * TAU
- ContinualAnimation.__init__(self, group, **kwargs)
+ self.add(submob)
+ self.add_updater(lambda m, dt: m.update(dt))
- def update_mobject(self, dt):
- for submob in self.mobject.submobjects:
+ def update(self, dt):
+ for submob in self.submobjects:
submob.jiggling_phase += dt * self.jiggles_per_second * TAU
submob.shift(
self.amplitude *
@@ -670,7 +674,7 @@ class TestVectorField(Scene):
min_magnitude=0,
max_magnitude=2,
)
- self.add(StreamLineAnimation(
+ self.add(AnimatedStreamLines(
lines,
line_anim_class=ShowPassingFlash
))
@@ -930,7 +934,7 @@ class CylinderModel(Scene):
line_anim_class = ShowPassingFlashWithThinningStrokeWidth
else:
line_anim_class = ShowPassingFlash
- return StreamLineAnimation(
+ return AnimatedStreamLines(
stream_lines,
line_anim_class=line_anim_class,
)
@@ -1447,7 +1451,7 @@ class IntroduceVectorField(Scene):
vector_field.func,
**self.stream_line_config
)
- stream_line_animation = StreamLineAnimation(
+ stream_line_animation = AnimatedStreamLines(
stream_lines,
**self.stream_line_animation_config
)
@@ -1771,7 +1775,7 @@ class DefineDivergence(ChangingElectricField):
self.vector_field.func,
**self.stream_line_config
)
- stream_line_animation = StreamLineAnimation(
+ stream_line_animation = AnimatedStreamLines(
stream_lines,
**self.stream_line_animation_config
)
@@ -1990,7 +1994,7 @@ class DivergenceAtSlowFastPoint(Scene):
self.vector_field.func,
**self.stream_lines_config
)
- stream_line_animation = StreamLineAnimation(stream_lines)
+ stream_line_animation = AnimatedStreamLines(stream_lines)
stream_line_animation.update(3)
self.add(stream_line_animation)
@@ -2292,7 +2296,7 @@ class PureCylinderFlow(Scene):
self.modify_flow(stream_lines)
- stream_line_animation = StreamLineAnimation(stream_lines)
+ stream_line_animation = AnimatedStreamLines(stream_lines)
stream_line_animation.update(3)
self.add(stream_line_animation)
@@ -2384,7 +2388,7 @@ class IntroduceCurl(IntroduceVectorField):
self.vector_field.func,
**self.stream_line_config
)
- stream_line_animation = StreamLineAnimation(
+ stream_line_animation = AnimatedStreamLines(
stream_lines,
**self.stream_line_animation_config
)
@@ -3453,7 +3457,7 @@ class PhaseSpaceOfPopulationModel(ShowTwoPopulations, PiCreatureScene, MovingCam
max_magnitude=vector_field.max_magnitude,
virtual_time=4,
)
- stream_line_animation = StreamLineAnimation(
+ stream_line_animation = AnimatedStreamLines(
stream_lines,
)
self.add(stream_line_animation)
@@ -4344,7 +4348,7 @@ class ZToHalfFlowNearWall(ComplexTransformationScene, MovingCameraScene):
stroke_width=2,
max_magnitude=10,
)
- stream_line_animation = StreamLineAnimation(stream_lines)
+ stream_line_animation = AnimatedStreamLines(stream_lines)
self.add(stream_line_animation)
self.wait(7)
diff --git a/old_projects/lost_lecture.py b/old_projects/lost_lecture.py
index c261f07a5..10fd67aa6 100644
--- a/old_projects/lost_lecture.py
+++ b/old_projects/lost_lecture.py
@@ -12,12 +12,16 @@ COBALT = "#0047AB"
# updater instead
-class Orbiting(ContinualAnimation):
+# TODO, this is untested after turning it from a
+# ContinualAnimation into a VGroup
+class Orbiting(VGroup):
CONFIG = {
"rate": 7.5,
}
def __init__(self, planet, star, ellipse, **kwargs):
+ VGroup.__init__(self, **kwargs)
+ self.add(planet)
self.planet = planet
self.star = star
self.ellipse = ellipse
@@ -25,9 +29,9 @@ class Orbiting(ContinualAnimation):
self.proportion = 0
planet.move_to(ellipse.point_from_proportion(0))
- ContinualAnimation.__init__(self, planet, **kwargs)
+ self.add_updater(lambda m, dt: m.update(dt))
- def update_mobject(self, dt):
+ def update(self, dt):
# time = self.internal_time
planet = self.planet
@@ -53,22 +57,27 @@ class Orbiting(ContinualAnimation):
)
-class SunAnimation(ContinualAnimation):
+# TODO, this is untested after turning it from a
+# ContinualAnimation into a Group
+class SunAnimation(Group):
CONFIG = {
"rate": 0.2,
"angle": 60 * DEGREES,
}
def __init__(self, sun, **kwargs):
+ Group.__init__(self, **kwargs)
self.sun = sun
self.rotated_sun = sun.deepcopy()
self.rotated_sun.rotate(60 * DEGREES)
- ContinualAnimation.__init__(
- self, Group(sun, self.rotated_sun), **kwargs
- )
+ self.time = 0
+
+ self.add(self.sun, self.rotated_sun)
+ self.add_updater(lambda m, dt: m.update(dt))
- def update_mobject(self, dt):
- time = self.internal_time
+ def update(self, dt):
+ time = self.time
+ self.time += dt
a = (np.sin(self.rate * time * TAU) + 1) / 2.0
self.rotated_sun.rotate(-self.angle)
self.rotated_sun.move_to(self.sun)
diff --git a/old_projects/nn/part1.py b/old_projects/nn/part1.py
index 62d70d62a..81c5ca4e4 100644
--- a/old_projects/nn/part1.py
+++ b/old_projects/nn/part1.py
@@ -5,6 +5,14 @@ import cv2
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from big_ol_pile_of_manim_imports import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
+
from nn.network import *
#force_skipping
diff --git a/old_projects/quaternions.py b/old_projects/quaternions.py
index 68d4763b1..26c26f91a 100644
--- a/old_projects/quaternions.py
+++ b/old_projects/quaternions.py
@@ -4141,7 +4141,7 @@ class ReferernceSpheresFelixView(ShowRotationsJustWithReferenceCircles):
ShowRotationsJustWithReferenceCircles.move_camera(self, **kwargs)
def begin_ambient_camera_rotation(self, rate):
- self.ambient_camera_rotation = ContinualAnimation(VectorizedPoint())
+ self.ambient_camera_rotation = VectorizedPoint()
def capture_mobjects_in_camera(self, mobjects, **kwargs):
mobs_on_xy = [
diff --git a/old_projects/uncertainty.py b/old_projects/uncertainty.py
index 3ecbfa942..c71981f39 100644
--- a/old_projects/uncertainty.py
+++ b/old_projects/uncertainty.py
@@ -1,10 +1,16 @@
# -*- coding: utf-8 -*-
-
import scipy
from big_ol_pile_of_manim_imports import *
from old_projects.fourier import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
FREQUENCY_COLOR = RED
USE_ALMOST_FOURIER_BY_DEFAULT = False
diff --git a/old_projects/waves.py b/old_projects/waves.py
index 8cb2f8e5f..b45276017 100644
--- a/old_projects/waves.py
+++ b/old_projects/waves.py
@@ -1,6 +1,14 @@
from big_ol_pile_of_manim_imports import *
+import warnings
+warnings.warn("""
+ Warning: This file makes use of
+ ContinualAnimation, which has since
+ been deprecated
+""")
+
+
E_COLOR = BLUE
M_COLOR = YELLOW