mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Factored out parts of Scene.play
This commit is contained in:
parent
ec638de1ec
commit
a1cead1570
1 changed files with 30 additions and 20 deletions
|
@ -371,7 +371,7 @@ class Scene(Container):
|
||||||
]))
|
]))
|
||||||
return time_progression
|
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 method
|
Each arg can either be an animation, or a mobject method
|
||||||
followed by that methods arguments (and potentially follow
|
followed by that methods arguments (and potentially follow
|
||||||
|
@ -430,6 +430,12 @@ class Scene(Container):
|
||||||
else:
|
else:
|
||||||
raise Exception("Invalid play arguments")
|
raise Exception("Invalid play arguments")
|
||||||
compile_method(state)
|
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 animations
|
return animations
|
||||||
|
|
||||||
def update_skipping_status(self):
|
def update_skipping_status(self):
|
||||||
|
@ -451,55 +457,59 @@ class Scene(Container):
|
||||||
self.num_plays += 1
|
self.num_plays += 1
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@handle_play_like_call
|
def begin_animations(self, animations):
|
||||||
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)
|
|
||||||
curr_mobjects = self.get_mobject_family_members()
|
curr_mobjects = self.get_mobject_family_members()
|
||||||
self.mobjects_from_last_animation = []
|
|
||||||
for animation in animations:
|
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
|
# Anything animated that's not already in the
|
||||||
# scene gets added to the scene
|
# scene gets added to the scene
|
||||||
mob = animation.mobject
|
mob = animation.mobject
|
||||||
if mob not in curr_mobjects:
|
if mob not in curr_mobjects:
|
||||||
self.add(mob)
|
self.add(mob)
|
||||||
curr_mobjects += mob.get_family()
|
curr_mobjects += mob.get_family()
|
||||||
self.mobjects_from_last_animation.append(mob)
|
|
||||||
# Begin animation
|
# Begin animation
|
||||||
animation.begin()
|
animation.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
|
# Paint all non-moving objects onto the screen, so they don't
|
||||||
# have to be rendered every frame
|
# have to be rendered every frame
|
||||||
|
moving_mobjects = self.get_moving_mobjects(*animations)
|
||||||
self.update_frame(excluded_mobjects=moving_mobjects)
|
self.update_frame(excluded_mobjects=moving_mobjects)
|
||||||
static_image = self.get_frame()
|
static_image = self.get_frame()
|
||||||
|
last_t = 0
|
||||||
for t in self.get_animation_time_progression(animations):
|
for t in self.get_animation_time_progression(animations):
|
||||||
dt = 1 / self.camera.frame_rate
|
dt = t - last_t
|
||||||
|
last_t = t
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
animation.update_mobjects(dt)
|
animation.update_mobjects(dt)
|
||||||
animation.interpolate(t / animation.run_time)
|
alpha = t / animation.run_time
|
||||||
|
animation.interpolate(alpha)
|
||||||
self.continual_update(dt)
|
self.continual_update(dt)
|
||||||
self.update_frame(moving_mobjects, static_image)
|
self.update_frame(moving_mobjects, static_image)
|
||||||
self.add_frames(self.get_frame())
|
self.add_frames(self.get_frame())
|
||||||
|
|
||||||
|
def finish_animations(self, animations):
|
||||||
for animation in animations:
|
for animation in animations:
|
||||||
animation.finish()
|
animation.finish()
|
||||||
animation.clean_up_from_scene(self)
|
animation.clean_up_from_scene(self)
|
||||||
|
self.mobjects_from_last_animation = [
|
||||||
|
anim.mobject for anim in animations
|
||||||
|
]
|
||||||
if self.skip_animations:
|
if self.skip_animations:
|
||||||
self.continual_update(self.get_run_time(animations))
|
self.continual_update(self.get_run_time(animations))
|
||||||
else:
|
else:
|
||||||
self.continual_update(0)
|
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):
|
def idle_stream(self):
|
||||||
self.file_writer.idle_stream()
|
self.file_writer.idle_stream()
|
||||||
|
|
Loading…
Add table
Reference in a new issue