From a4272d11a243535a9626d10551acc69b345c5635 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 16 Dec 2022 15:21:31 -0800 Subject: [PATCH] Finish last(?) digest_config vestige --- manimlib/animation/animation.py | 12 +++++++++--- manimlib/scene/scene.py | 25 +++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.py index 24d40459..a8ece9ca 100644 --- a/manimlib/animation/animation.py +++ b/manimlib/animation/animation.py @@ -4,7 +4,6 @@ from copy import deepcopy from manimlib.mobject.mobject import _AnimationBuilder from manimlib.mobject.mobject import Mobject -from manimlib.utils.config_ops import digest_config from manimlib.utils.rate_functions import smooth from manimlib.utils.rate_functions import squish_rate_func from manimlib.utils.simple_functions import clip @@ -128,8 +127,15 @@ class Animation(object): def copy(self): return deepcopy(self) - def update_config(self, **kwargs): - digest_config(self, kwargs) + def update_rate_info( + self, + run_time: float | None = None, + rate_func: Callable[[float], float] | None = None, + lag_ratio: float | None = None, + ): + self.run_time = run_time or self.run_time + self.rate_func = rate_func or self.rate_func + self.lag_ratio = lag_ratio or self.lag_ratio return self # Methods for interpolation, the mean of an Animation diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index c852ff6a..aef46e68 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -502,6 +502,7 @@ class Scene(object): self, animations: Iterable[Animation] ) -> list[float] | np.ndarray | ProgressDisplay: + animations = list(animations) run_time = self.get_run_time(animations) description = f"{self.num_plays} {animations[0]}" if len(animations) > 1: @@ -520,18 +521,6 @@ class Scene(object): kw["override_skip_animations"] = True return self.get_time_progression(duration, **kw) - def prepare_animations( - self, - proto_animations: list[Animation | _AnimationBuilder], - animation_config: dict, - ): - animations = list(map(prepare_animation, proto_animations)) - for anim in animations: - # This is where kwargs to play like run_time and rate_func - # get applied to all animations - anim.update_config(**animation_config) - return animations - def handle_play_like_call(func): @wraps(func) def wrapper(self, *args, **kwargs): @@ -601,11 +590,19 @@ class Scene(object): self.update_mobjects(0) @handle_play_like_call - def play(self, *proto_animations, **animation_config) -> None: + def play( + self, + *proto_animations: Animation | _AnimationBuilder, + run_time: float | None = None, + rate_func: Callable[[float], float] | None = None, + lag_ratio: float | None = None, + ) -> None: if len(proto_animations) == 0: log.warning("Called Scene.play with no animations") return - animations = self.prepare_animations(proto_animations, animation_config) + animations = list(map(prepare_animation, proto_animations)) + for anim in animations: + anim.update_rate_info(run_time, rate_func, lag_ratio) self.begin_animations(animations) self.progress_through_animations(animations) self.finish_animations(animations)