From 9a9cc8bdacb7541b7cd4a52ad705abc21f3e27fe Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 13 Jan 2022 20:29:58 -0800 Subject: [PATCH] Add presenter mode to scenes with -p option --- manimlib/config.py | 7 +++++++ manimlib/extract_scene.py | 1 + manimlib/scene/scene.py | 29 +++++++++++++++++++---------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/manimlib/config.py b/manimlib/config.py index fef3d409..6dc65941 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -65,6 +65,12 @@ def parse_cli(): action="store_true", help="Show window in full screen", ) + parser.add_argument( + "-p", "--presenter_mode", + action="store_true", + help="scene will stay paused during wait calls until " + "space bar or right arrow is hit, like a slide show" + ) parser.add_argument( "-g", "--save_pngs", action="store_true", @@ -306,6 +312,7 @@ def get_configuration(args): "start_at_animation_number": args.start_at_animation_number, "end_at_animation_number": None, "preview": not write_file, + "presenter_mode": args.presenter_mode, "leave_progress_bars": args.leave_progress_bars, } diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py index f6bbd0b9..abec96ec 100644 --- a/manimlib/extract_scene.py +++ b/manimlib/extract_scene.py @@ -64,6 +64,7 @@ def get_scene_config(config): "end_at_animation_number", "leave_progress_bars", "preview", + "presenter_mode", ] ]) diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index c67d2850..d52894b5 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -36,6 +36,7 @@ class Scene(object): "end_at_animation_number": None, "leave_progress_bars": False, "preview": True, + "presenter_mode": False, "linger_after_completion": True, } @@ -62,6 +63,7 @@ class Scene(object): # Items associated with interaction self.mouse_point = Point() self.mouse_drag_point = Point() + self.hold_on_wait = not self.presenter_mode # Much nicer to work with deterministic scenes if self.random_seed is not None: @@ -485,16 +487,21 @@ class Scene(object): def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None): self.update_mobjects(dt=0) # Any problems with this? self.lock_static_mobject_data() - time_progression = self.get_wait_time_progression(duration, stop_condition) - last_t = 0 - for t in time_progression: - dt = t - last_t - last_t = t - self.update_frame(dt) - self.emit_frame() - if stop_condition is not None and stop_condition(): - time_progression.close() - break + if self.presenter_mode and not self.skip_animations: + while self.hold_on_wait: + self.update_frame(dt=1 / self.camera.frame_rate) + self.hold_on_wait = True + else: + time_progression = self.get_wait_time_progression(duration, stop_condition) + last_t = 0 + for t in time_progression: + dt = t - last_t + last_t = t + self.update_frame(dt) + self.emit_frame() + if stop_condition is not None and stop_condition(): + time_progression.close() + break self.unlock_mobject_data() return self @@ -615,6 +622,8 @@ class Scene(object): self.camera.frame.to_default_state() elif char == "q": self.quit_interaction = True + elif char == " ": + self.hold_on_wait = False def on_resize(self, width: int, height: int): self.camera.reset_pixel_shape(width, height)