From e632be304d07e1ca5fa69363c7fefb3131c37b1a Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Mon, 19 Feb 2018 16:50:58 -0800 Subject: [PATCH] Removed sync_animation_run_times_and_rate_funcs, and changed the implementaiton of Scene.play and AnimationGroup so as to not change the run_time and rate_func of the animations passed in. --- animation/animation.py | 13 ------------- animation/simple_animations.py | 11 ++++++----- scene/scene.py | 8 +++++--- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/animation/animation.py b/animation/animation.py index 45156f59..1e4b5594 100644 --- a/animation/animation.py +++ b/animation/animation.py @@ -129,19 +129,6 @@ class Animation(object): return self -def sync_animation_run_times_and_rate_funcs(*animations, **kwargs): - for animation in animations: - animation.update_config(**kwargs) - max_run_time = max([a.run_time for a in animations]) - for animation in animations: - if animation.run_time != max_run_time: - new_rate_func = squish_rate_func( - animation.get_rate_func(), - 0, float(animation.run_time)/max_run_time - ) - animation.set_rate_func(new_rate_func) - animation.set_run_time(max_run_time) - diff --git a/animation/simple_animations.py b/animation/simple_animations.py index dac11771..801181b9 100644 --- a/animation/simple_animations.py +++ b/animation/simple_animations.py @@ -7,7 +7,6 @@ from mobject import Mobject, Group from mobject.vectorized_mobject import VMobject from mobject.tex_mobject import TextMobject from animation import Animation -from animation import sync_animation_run_times_and_rate_funcs from transform import Transform class Rotating(Animation): @@ -492,15 +491,17 @@ class AnimationGroup(Animation): self.empty = True self.run_time = 0 else: - # Should really make copies of animations, instead of messing with originals... - sync_animation_run_times_and_rate_funcs(*sub_anims, **kwargs) + for anim in sub_anims: + # If AnimationGroup is called with any configuration, + # it is propagated to the sub_animations + anim.update_config(**kwargs) self.run_time = max([a.run_time for a in sub_anims]) everything = Mobject(*[a.mobject for a in sub_anims]) Animation.__init__(self, everything, **kwargs) - def update_mobject(self, alpha): + def update(self, alpha): for anim in self.sub_anims: - anim.update(alpha) + anim.update(alpha * self.run_time / anim.run_time) def clean_up(self, *args, **kwargs): for anim in self.sub_anims: diff --git a/scene/scene.py b/scene/scene.py index 769ce11a..5691b943 100644 --- a/scene/scene.py +++ b/scene/scene.py @@ -17,7 +17,6 @@ from camera import Camera from tk_scene import TkSceneRoot from mobject import Mobject, VMobject from animation import Animation -from animation.animation import sync_animation_run_times_and_rate_funcs from animation.transform import MoveToTarget from animation.continual_animation import ContinualAnimation from container import * @@ -336,7 +335,7 @@ class Scene(Container): return time_progression def get_animation_time_progression(self, animations): - run_time = animations[0].run_time + run_time = np.max([animation.run_time for animation in animations]) time_progression = self.get_time_progression(run_time) time_progression.set_description("".join([ "Animation %d: "%self.num_plays, @@ -422,7 +421,10 @@ class Scene(Container): animations = self.compile_play_args_to_animation_list(*args) - sync_animation_run_times_and_rate_funcs(*animations, **kwargs) + for animation in animations: + # This is where kwargs to play like run_time and rate_func + # get applied to all animations + animation.update_config(**kwargs) moving_mobjects = self.get_moving_mobjects(*animations) self.update_frame(excluded_mobjects = moving_mobjects) static_image = self.get_frame()