mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Added Scene.wait_until and changed time_progression defaults
This commit is contained in:
parent
236d67456a
commit
633050c02a
1 changed files with 25 additions and 14 deletions
|
@ -385,14 +385,15 @@ class Scene(Container):
|
||||||
return mobjects[i:]
|
return mobjects[i:]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_time_progression(self, run_time, n_iterations=None):
|
def get_time_progression(self, run_time, n_iterations=None, override_skip_animations=False):
|
||||||
if self.skip_animations:
|
if self.skip_animations and not override_skip_animations:
|
||||||
times = [run_time]
|
times = [run_time]
|
||||||
else:
|
else:
|
||||||
step = self.frame_duration
|
step = self.frame_duration
|
||||||
times = np.arange(0, run_time, step)
|
times = np.arange(0, run_time, step)
|
||||||
time_progression = ProgressDisplay(
|
time_progression = ProgressDisplay(
|
||||||
times, total=n_iterations
|
times, total=n_iterations,
|
||||||
|
leave=False,
|
||||||
)
|
)
|
||||||
return time_progression
|
return time_progression
|
||||||
|
|
||||||
|
@ -400,7 +401,7 @@ class Scene(Container):
|
||||||
run_time = np.max([animation.run_time for animation in animations])
|
run_time = np.max([animation.run_time for animation in animations])
|
||||||
time_progression = self.get_time_progression(run_time)
|
time_progression = self.get_time_progression(run_time)
|
||||||
time_progression.set_description("".join([
|
time_progression.set_description("".join([
|
||||||
"Animation %d: " % self.num_plays,
|
"Animation {}: ".format(self.num_plays),
|
||||||
str(animations[0]),
|
str(animations[0]),
|
||||||
(", etc." if len(animations) > 1 else ""),
|
(", etc." if len(animations) > 1 else ""),
|
||||||
]))
|
]))
|
||||||
|
@ -543,25 +544,35 @@ class Scene(Container):
|
||||||
return self.mobjects_from_last_animation
|
return self.mobjects_from_last_animation
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
def get_wait_time_progression(self, duration, stop_condition):
|
||||||
|
if stop_condition is not None:
|
||||||
|
time_progression = self.get_time_progression(
|
||||||
|
duration,
|
||||||
|
n_iterations=-1, # So it doesn't show % progress
|
||||||
|
override_skip_animations=True
|
||||||
|
|
||||||
|
)
|
||||||
|
time_progression.set_description(
|
||||||
|
"Waiting for {}".format(stop_condition.__name__)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
time_progression = self.get_time_progression(duration)
|
||||||
|
time_progression.set_description(
|
||||||
|
"Waiting {}".format(self.num_plays)
|
||||||
|
)
|
||||||
|
return time_progression
|
||||||
|
|
||||||
@handle_play_like_call
|
@handle_play_like_call
|
||||||
def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
|
def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
|
||||||
if self.should_continually_update():
|
if self.should_continually_update():
|
||||||
total_time = 0
|
total_time = 0
|
||||||
if stop_condition is not None:
|
time_progression = self.get_wait_time_progression(duration, stop_condition)
|
||||||
time_progression = self.get_time_progression(
|
|
||||||
duration,
|
|
||||||
n_iterations=-1 # So it doesn't show % progress
|
|
||||||
)
|
|
||||||
time_progression.set_description(
|
|
||||||
"Waiting for {}".format(stop_condition.__name__)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
time_progression = self.get_time_progression(duration)
|
|
||||||
for t in time_progression:
|
for t in time_progression:
|
||||||
self.continual_update(dt=t - total_time)
|
self.continual_update(dt=t - total_time)
|
||||||
self.update_frame()
|
self.update_frame()
|
||||||
self.add_frames(self.get_frame())
|
self.add_frames(self.get_frame())
|
||||||
if stop_condition and stop_condition():
|
if stop_condition and stop_condition():
|
||||||
|
time_progression.clear()
|
||||||
break
|
break
|
||||||
total_time = t
|
total_time = t
|
||||||
elif self.skip_animations:
|
elif self.skip_animations:
|
||||||
|
|
Loading…
Add table
Reference in a new issue