A community-maintained Python framework for creating mathematical animations.
Factored out parts of Scene.play
Grant Sandersona1cead1570be
diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.pyindex f71f6a717..95cb567e7 100644--- a/manimlib/scene/scene.py+++ b/manimlib/scene/scene.py@@ -371,7 +371,7 @@ class Scene(Container):]))return time_progression- def compile_play_args_to_animation_list(self, *args):+ def compile_play_args_to_animation_list(self, *args, **kwargs):"""Each arg can either be an animation, or a mobject methodfollowed by that methods arguments (and potentially follow@@ -430,6 +430,12 @@ class Scene(Container):else:raise Exception("Invalid play arguments")compile_method(state)++ 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)+return animationsdef update_skipping_status(self):@@ -451,55 +457,59 @@ class Scene(Container):self.num_plays += 1return wrapper- @handle_play_like_call- def play(self, *args, **kwargs):- if len(args) == 0:- warnings.warn("Called Scene.play with no animations")- return-- animations = self.compile_play_args_to_animation_list(*args)+ def begin_animations(self, animations):curr_mobjects = self.get_mobject_family_members()- self.mobjects_from_last_animation = []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)# Anything animated that's not already in the# scene gets added to the scenemob = animation.mobjectif mob not in curr_mobjects:self.add(mob)curr_mobjects += mob.get_family()- self.mobjects_from_last_animation.append(mob)# Begin animationanimation.begin()- moving_mobjects = self.get_moving_mobjects(*animations)-+ def progress_through_animations(self, animations):# Paint all non-moving objects onto the screen, so they don't# have to be rendered every frame+ moving_mobjects = self.get_moving_mobjects(*animations)self.update_frame(excluded_mobjects=moving_mobjects)static_image = self.get_frame()+ last_t = 0for t in self.get_animation_time_progression(animations):- dt = 1 / self.camera.frame_rate+ dt = t - last_t+ last_t = tfor animation in animations:animation.update_mobjects(dt)- animation.interpolate(t / animation.run_time)-+ alpha = t / animation.run_time+ animation.interpolate(alpha)self.continual_update(dt)self.update_frame(moving_mobjects, static_image)self.add_frames(self.get_frame())+ def finish_animations(self, animations):for animation in animations:animation.finish()animation.clean_up_from_scene(self)-+ self.mobjects_from_last_animation = [+ anim.mobject for anim in animations+ ]if self.skip_animations:self.continual_update(self.get_run_time(animations))else:self.continual_update(0)- return self+ @handle_play_like_call+ def play(self, *args, **kwargs):+ if len(args) == 0:+ warnings.warn("Called Scene.play with no animations")+ return+ animations = self.compile_play_args_to_animation_list(+ *args, **kwargs+ )+ self.begin_animations(animations, **kwargs)+ self.progress_through_animations(animations)+ self.finish_animations(animations)def idle_stream(self):self.file_writer.idle_stream()