Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixes to ContinualAnimation

Grant Sandersona954a0985756
diff --git a/animation/continual_animation.py b/animation/continual_animation.py
index 3dcb654c0..a87087cfb 100644
--- a/animation/continual_animation.py
+++ b/animation/continual_animation.py
@@ -5,22 +5,40 @@ class ContinualAnimation(object):
CONFIG = {
"start_up_time" : 1,
"wind_down_time" : 1,
+ "end_time" : np.inf,
}
def __init__(self, mobject, **kwargs):
mobject = instantiate(mobject)
assert(isinstance(mobject, Mobject))
digest_config(self, kwargs, locals())
- self.total_time = 0
+ 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):
- if self.total_time < self.start_up_time:
- dt *= float(self.total_time+dt)/self.start_time
- self.total_time += 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):
diff --git a/constants.py b/constants.py
index 3fda24c5c..aca5f5a54 100644
--- a/constants.py
+++ b/constants.py
@@ -63,7 +63,8 @@ THIS_DIR = os.path.dirname(os.path.realpath(__file__))
FILE_DIR = os.path.join(THIS_DIR, "files")
IMAGE_DIR = os.path.join(FILE_DIR, "images")
GIF_DIR = os.path.join(FILE_DIR, "gifs")
-MOVIE_DIR = os.path.join(FILE_DIR, "movies")
+# MOVIE_DIR = os.path.join(FILE_DIR, "movies")
+MOVIE_DIR = os.path.join("/Users/grant/Dropbox/Bell's Project/", "movies")
STAGED_SCENES_DIR = os.path.join(FILE_DIR, "staged_scenes")
TEX_DIR = os.path.join(FILE_DIR, "Tex")
TEX_IMAGE_DIR = os.path.join(IMAGE_DIR, "Tex")
diff --git a/scene/scene.py b/scene/scene.py
index 007bfe5a9..91e834456 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -126,12 +126,16 @@ class Scene(object):
continual_animation.update(dt_multiplier*self.frame_duration)
def wind_down(self, *continual_animations, **kwargs):
- run_time = kwargs.get("run_time", 1)
+ wind_down_time = kwargs.get("wind_down_time", 1)
for continual_animation in continual_animations:
- continual_animation.begin_wind_down(run_time)
- self.dither(run_time)
- ##TODO
-
+ continual_animation.begin_wind_down(wind_down_time)
+ self.dither(wind_down_time)
+ #TODO, this is not done with the remove method so as to
+ #keep the relevant mobjects. Better way?
+ self.continual_animations = filter(
+ lambda ca : ca in continual_animations,
+ self.continual_animations
+ )
#
def extract_mobject_family_members(self, *mobjects):
diff --git a/waves.py b/waves.py
index f84bd3567..27f0da64f 100644
--- a/waves.py
+++ b/waves.py
@@ -45,7 +45,7 @@ class OscillatingVector(ContinualAnimation):
def update_mobject(self, dt):
f = self.frequency
- t = self.total_time
+ t = self.internal_time
angle = 2*np.pi*f*t
vect = np.array([
self.A_x*np.exp(complex(0, angle + self.phi_x)),
@@ -73,10 +73,14 @@ class Test(Scene):
)
randy = Randolph()
- self.add(randy, wiggle)
- self.dither(2)
- self.play(FadeOut(E_vect))
- self.dither(2)
+ self.add(randy)
+ self.play(ShowCreation(wiggle.mobject))
+ self.add(wiggle)
+ self.dither(4)
+ self.wind_down(wiggle)
+ self.dither()
+ # self.play(FadeOut(E_vect))
+ # self.dither(2)