2022-02-14 21:22:18 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import time
|
2018-03-31 15:11:35 -07:00
|
|
|
import random
|
2022-02-14 21:22:18 +08:00
|
|
|
import inspect
|
2019-07-26 16:45:52 +08:00
|
|
|
import platform
|
2020-02-19 23:13:29 -08:00
|
|
|
import itertools as it
|
2020-08-16 11:59:07 +02:00
|
|
|
from functools import wraps
|
2022-02-14 21:22:18 +08:00
|
|
|
from typing import Iterable, Callable
|
2018-03-31 15:11:35 -07:00
|
|
|
|
|
|
|
from tqdm import tqdm as ProgressDisplay
|
2018-12-24 12:37:51 -08:00
|
|
|
import numpy as np
|
2015-03-22 16:15:29 -06:00
|
|
|
|
2021-02-10 07:43:46 -06:00
|
|
|
from manimlib.animation.animation import prepare_animation
|
2020-02-04 15:28:50 -08:00
|
|
|
from manimlib.animation.transform import MoveToTarget
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.camera.camera import Camera
|
2021-01-05 23:14:16 -08:00
|
|
|
from manimlib.constants import DEFAULT_WAIT_TIME
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.mobject.mobject import Mobject
|
2021-10-16 13:04:52 +08:00
|
|
|
from manimlib.mobject.mobject import Point
|
2019-01-24 21:47:40 -08:00
|
|
|
from manimlib.scene.scene_file_writer import SceneFileWriter
|
2021-01-03 12:29:05 -08:00
|
|
|
from manimlib.utils.config_ops import digest_config
|
2020-01-15 18:30:58 -08:00
|
|
|
from manimlib.utils.family_ops import extract_mobject_family_members
|
|
|
|
from manimlib.utils.family_ops import restructure_list_to_exclude_certain_family_members
|
2021-02-02 16:04:50 +05:30
|
|
|
from manimlib.event_handler.event_type import EventType
|
|
|
|
from manimlib.event_handler import EVENT_DISPATCHER
|
2021-10-07 17:37:10 +08:00
|
|
|
from manimlib.logger import log
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
from typing import TYPE_CHECKING
|
2022-02-16 21:08:25 +08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from PIL.Image import Image
|
|
|
|
from manimlib.animation.animation import Animation
|
|
|
|
|
2018-12-27 09:41:41 -08:00
|
|
|
|
2021-01-03 12:29:05 -08:00
|
|
|
class Scene(object):
|
2016-02-27 16:32:53 -08:00
|
|
|
CONFIG = {
|
2020-02-11 19:51:19 -08:00
|
|
|
"window_config": {},
|
|
|
|
"camera_class": Camera,
|
2018-04-06 13:58:59 -07:00
|
|
|
"camera_config": {},
|
2019-01-24 21:47:40 -08:00
|
|
|
"file_writer_config": {},
|
2018-04-06 13:58:59 -07:00
|
|
|
"skip_animations": False,
|
2019-02-15 20:05:16 -08:00
|
|
|
"always_update_mobjects": False,
|
2018-04-06 13:58:59 -07:00
|
|
|
"random_seed": 0,
|
|
|
|
"start_at_animation_number": None,
|
|
|
|
"end_at_animation_number": None,
|
2019-01-16 11:10:43 -08:00
|
|
|
"leave_progress_bars": False,
|
2020-02-11 19:51:19 -08:00
|
|
|
"preview": True,
|
2022-02-13 15:16:16 -08:00
|
|
|
"presenter_mode": False,
|
2020-02-22 13:20:22 -08:00
|
|
|
"linger_after_completion": True,
|
2022-03-22 10:36:48 -07:00
|
|
|
"pan_sensitivity": 3,
|
2015-09-28 16:25:18 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2015-09-28 16:25:18 -07:00
|
|
|
def __init__(self, **kwargs):
|
2021-01-03 12:29:05 -08:00
|
|
|
digest_config(self, kwargs)
|
2020-02-11 19:51:19 -08:00
|
|
|
if self.preview:
|
2021-02-11 12:21:06 -08:00
|
|
|
from manimlib.window import Window
|
2021-02-10 14:48:00 -08:00
|
|
|
self.window = Window(scene=self, **self.window_config)
|
2020-02-13 10:42:07 -08:00
|
|
|
self.camera_config["ctx"] = self.window.ctx
|
2021-08-21 17:07:20 -07:00
|
|
|
self.camera_config["frame_rate"] = 30 # Where's that 30 from?
|
2020-02-13 10:42:07 -08:00
|
|
|
else:
|
|
|
|
self.window = None
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
self.camera: Camera = self.camera_class(**self.camera_config)
|
2020-02-04 15:28:50 -08:00
|
|
|
self.file_writer = SceneFileWriter(self, **self.file_writer_config)
|
2022-02-14 21:22:18 +08:00
|
|
|
self.mobjects: list[Mobject] = [self.camera.frame]
|
|
|
|
self.num_plays: int = 0
|
|
|
|
self.time: float = 0
|
|
|
|
self.skip_time: float = 0
|
|
|
|
self.original_skipping_status: bool = self.skip_animations
|
2021-12-07 10:03:10 -08:00
|
|
|
if self.start_at_animation_number is not None:
|
|
|
|
self.skip_animations = True
|
2020-02-14 15:30:44 -08:00
|
|
|
|
2020-02-14 16:26:49 -08:00
|
|
|
# Items associated with interaction
|
2020-02-14 15:30:44 -08:00
|
|
|
self.mouse_point = Point()
|
|
|
|
self.mouse_drag_point = Point()
|
2022-02-14 07:52:06 -08:00
|
|
|
self.hold_on_wait = self.presenter_mode
|
2020-02-14 15:30:44 -08:00
|
|
|
|
2021-01-05 22:37:28 -08:00
|
|
|
# Much nicer to work with deterministic scenes
|
2017-12-06 15:17:59 -08:00
|
|
|
if self.random_seed is not None:
|
|
|
|
random.seed(self.random_seed)
|
|
|
|
np.random.seed(self.random_seed)
|
2015-10-29 13:45:28 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def run(self) -> None:
|
|
|
|
self.virtual_animation_start_time: float = 0
|
|
|
|
self.real_animation_start_time: float = time.time()
|
2021-01-23 11:02:22 -08:00
|
|
|
self.file_writer.begin()
|
2021-01-05 22:37:28 -08:00
|
|
|
|
2016-08-10 10:26:07 -07:00
|
|
|
self.setup()
|
2018-02-19 17:24:17 -08:00
|
|
|
try:
|
2019-01-24 21:47:40 -08:00
|
|
|
self.construct()
|
2018-02-19 17:24:17 -08:00
|
|
|
except EndSceneEarlyException:
|
2019-01-24 21:47:40 -08:00
|
|
|
pass
|
2019-01-04 12:47:48 -08:00
|
|
|
self.tear_down()
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def setup(self) -> None:
|
2017-04-21 17:40:49 -07:00
|
|
|
"""
|
|
|
|
This is meant to be implement by any scenes which
|
2018-02-26 19:07:57 -08:00
|
|
|
are comonly subclassed, and have some common setup
|
2017-04-21 17:40:49 -07:00
|
|
|
involved before the construct method is called.
|
|
|
|
"""
|
|
|
|
pass
|
2016-08-10 10:26:07 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def construct(self) -> None:
|
2020-02-22 13:20:22 -08:00
|
|
|
# Where all the animation happens
|
2020-02-11 19:51:19 -08:00
|
|
|
# To be implemented in subclasses
|
|
|
|
pass
|
2015-03-22 16:15:29 -06:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def tear_down(self) -> None:
|
2020-02-14 15:30:44 -08:00
|
|
|
self.stop_skipping()
|
2020-02-11 19:51:19 -08:00
|
|
|
self.file_writer.finish()
|
2020-02-22 13:20:22 -08:00
|
|
|
if self.window and self.linger_after_completion:
|
2020-02-13 10:42:07 -08:00
|
|
|
self.interact()
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def interact(self) -> None:
|
2020-02-13 10:42:07 -08:00
|
|
|
# If there is a window, enter a loop
|
|
|
|
# which updates the frame while under
|
|
|
|
# the hood calling the pyglet event loop
|
2022-04-14 16:27:58 -07:00
|
|
|
log.info(
|
|
|
|
"Tips: You are now in the interactive mode. Now you can use the keyboard"
|
|
|
|
" and the mouse to interact with the scene. Just press `q` if you want to quit."
|
|
|
|
)
|
2020-02-14 16:26:49 -08:00
|
|
|
self.quit_interaction = False
|
2022-04-14 16:27:58 -07:00
|
|
|
self.refresh_static_mobjects()
|
2021-01-06 12:48:58 -08:00
|
|
|
while not (self.window.is_closing or self.quit_interaction):
|
2021-08-22 14:57:32 -07:00
|
|
|
self.update_frame(1 / self.camera.frame_rate)
|
2020-02-14 16:26:49 -08:00
|
|
|
if self.window.is_closing:
|
|
|
|
self.window.destroy()
|
2020-02-04 15:28:50 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def embed(self, close_scene_on_exit: bool = True) -> None:
|
2020-02-23 22:59:29 +00:00
|
|
|
if not self.preview:
|
|
|
|
# If the scene is just being
|
|
|
|
# written, ignore embed calls
|
|
|
|
return
|
2020-02-14 15:30:44 -08:00
|
|
|
self.stop_skipping()
|
2020-02-22 13:20:22 -08:00
|
|
|
self.linger_after_completion = False
|
2020-02-14 15:30:44 -08:00
|
|
|
self.update_frame()
|
2021-02-23 11:59:08 -08:00
|
|
|
|
2021-10-11 06:22:41 -07:00
|
|
|
# Save scene state at the point of embedding
|
|
|
|
self.save_state()
|
|
|
|
|
2021-02-11 12:21:06 -08:00
|
|
|
from IPython.terminal.embed import InteractiveShellEmbed
|
2020-02-14 15:30:44 -08:00
|
|
|
shell = InteractiveShellEmbed()
|
2020-02-14 16:26:49 -08:00
|
|
|
# Have the frame update after each command
|
2022-04-14 16:27:58 -07:00
|
|
|
shell.events.register('post_run_cell', lambda *a, **kw: self.refresh_static_mobjects())
|
2020-02-14 16:26:49 -08:00
|
|
|
shell.events.register('post_run_cell', lambda *a, **kw: self.update_frame())
|
2021-01-19 13:52:57 -08:00
|
|
|
# Use the locals of the caller as the local namespace
|
2021-08-07 22:25:26 +07:00
|
|
|
# once embedded, and add a few custom shortcuts
|
2021-01-19 13:52:57 -08:00
|
|
|
local_ns = inspect.currentframe().f_back.f_locals
|
|
|
|
local_ns["touch"] = self.interact
|
2021-02-03 14:19:20 -08:00
|
|
|
for term in ("play", "wait", "add", "remove", "clear", "save_state", "restore"):
|
2021-01-19 13:52:57 -08:00
|
|
|
local_ns[term] = getattr(self, term)
|
2021-10-16 13:04:52 +08:00
|
|
|
log.info("Tips: Now the embed iPython terminal is open. But you can't interact with"
|
2021-11-12 15:47:23 -08:00
|
|
|
" the window directly. To do so, you need to type `touch()` or `self.interact()`")
|
2021-01-19 13:52:57 -08:00
|
|
|
shell(local_ns=local_ns, stack_depth=2)
|
2022-02-13 15:16:16 -08:00
|
|
|
# End scene when exiting an embed
|
|
|
|
if close_scene_on_exit:
|
|
|
|
raise EndSceneEarlyException()
|
2020-02-14 15:30:44 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def __str__(self) -> str:
|
2019-01-10 17:06:22 -08:00
|
|
|
return self.__class__.__name__
|
2015-04-03 16:41:25 -07:00
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
# Only these methods should touch the camera
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_image(self) -> Image:
|
2016-02-23 22:29:32 -08:00
|
|
|
return self.camera.get_image()
|
2015-10-29 13:45:28 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def show(self) -> None:
|
2021-01-05 22:37:28 -08:00
|
|
|
self.update_frame(ignore_skipping=True)
|
|
|
|
self.get_image().show()
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def update_frame(self, dt: float = 0, ignore_skipping: bool = False) -> None:
|
2020-02-14 11:55:07 -08:00
|
|
|
self.increment_time(dt)
|
2020-02-17 12:14:40 -08:00
|
|
|
self.update_mobjects(dt)
|
2019-01-24 21:47:40 -08:00
|
|
|
if self.skip_animations and not ignore_skipping:
|
2018-02-19 17:24:17 -08:00
|
|
|
return
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2020-02-13 10:42:07 -08:00
|
|
|
if self.window:
|
|
|
|
self.window.clear()
|
2020-02-04 15:28:50 -08:00
|
|
|
self.camera.clear()
|
2020-02-17 12:14:40 -08:00
|
|
|
self.camera.capture(*self.mobjects)
|
2020-02-14 11:55:07 -08:00
|
|
|
|
2020-02-13 10:42:07 -08:00
|
|
|
if self.window:
|
|
|
|
self.window.swap_buffers()
|
2020-02-18 22:30:43 -08:00
|
|
|
vt = self.time - self.virtual_animation_start_time
|
|
|
|
rt = time.time() - self.real_animation_start_time
|
|
|
|
if rt < vt:
|
|
|
|
self.update_frame(0)
|
2020-02-14 11:55:07 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def emit_frame(self) -> None:
|
2020-02-11 19:51:19 -08:00
|
|
|
if not self.skip_animations:
|
|
|
|
self.file_writer.write_frame(self.camera)
|
|
|
|
|
2021-01-05 22:37:28 -08:00
|
|
|
# Related to updating
|
2022-02-14 21:22:18 +08:00
|
|
|
def update_mobjects(self, dt: float) -> None:
|
2019-01-29 14:40:44 -08:00
|
|
|
for mobject in self.mobjects:
|
2018-08-12 12:17:32 -07:00
|
|
|
mobject.update(dt)
|
2017-08-24 11:43:38 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def should_update_mobjects(self) -> bool:
|
2019-02-15 20:05:16 -08:00
|
|
|
return self.always_update_mobjects or any([
|
2020-02-14 15:30:44 -08:00
|
|
|
len(mob.get_family_updaters()) > 0
|
|
|
|
for mob in self.mobjects
|
2018-08-12 12:17:32 -07:00
|
|
|
])
|
2017-08-24 19:05:04 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def has_time_based_updaters(self) -> bool:
|
2021-12-07 10:05:33 -08:00
|
|
|
return any([
|
|
|
|
sm.has_time_based_updater()
|
|
|
|
for mob in self.mobjects()
|
|
|
|
for sm in mob.get_family()
|
|
|
|
])
|
|
|
|
|
2021-01-05 22:37:28 -08:00
|
|
|
# Related to time
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_time(self) -> float:
|
2019-01-10 17:06:22 -08:00
|
|
|
return self.time
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def increment_time(self, dt: float) -> None:
|
2020-02-14 11:55:07 -08:00
|
|
|
self.time += dt
|
2019-01-10 17:06:22 -08:00
|
|
|
|
2021-01-05 22:37:28 -08:00
|
|
|
# Related to internal mobject organization
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_top_level_mobjects(self) -> list[Mobject]:
|
2017-02-09 21:09:51 -08:00
|
|
|
# Return only those which are not in the family
|
|
|
|
# of another mobject from the scene
|
|
|
|
mobjects = self.get_mobjects()
|
2018-08-21 19:15:16 -07:00
|
|
|
families = [m.get_family() for m in mobjects]
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2017-02-09 21:09:51 -08:00
|
|
|
def is_top_level(mobject):
|
|
|
|
num_families = sum([
|
2017-10-05 21:03:30 -05:00
|
|
|
(mobject in family)
|
2017-02-09 21:09:51 -08:00
|
|
|
for family in families
|
|
|
|
])
|
|
|
|
return num_families == 1
|
2018-08-09 17:56:05 -07:00
|
|
|
return list(filter(is_top_level, mobjects))
|
2017-10-05 21:03:30 -05:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_mobject_family_members(self) -> list[Mobject]:
|
2020-01-15 18:30:58 -08:00
|
|
|
return extract_mobject_family_members(self.mobjects)
|
2018-08-13 14:13:30 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def add(self, *new_mobjects: Mobject):
|
2015-03-26 22:49:22 -06:00
|
|
|
"""
|
2019-02-15 20:05:16 -08:00
|
|
|
Mobjects will be displayed, from background to
|
|
|
|
foreground in the order with which they are added.
|
2015-03-26 22:49:22 -06:00
|
|
|
"""
|
2020-01-15 18:30:58 -08:00
|
|
|
self.remove(*new_mobjects)
|
|
|
|
self.mobjects += new_mobjects
|
2015-06-09 11:26:12 -07:00
|
|
|
return self
|
2015-03-22 16:15:29 -06:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def add_mobjects_among(self, values: Iterable):
|
2015-10-09 19:53:38 -07:00
|
|
|
"""
|
2019-02-15 20:05:16 -08:00
|
|
|
This is meant mostly for quick prototyping,
|
|
|
|
e.g. to add all mobjects defined up to a point,
|
|
|
|
call self.add_mobjects_among(locals().values())
|
2015-10-09 19:53:38 -07:00
|
|
|
"""
|
2019-02-15 20:05:16 -08:00
|
|
|
self.add(*filter(
|
|
|
|
lambda m: isinstance(m, Mobject),
|
|
|
|
values
|
|
|
|
))
|
2015-11-02 13:03:01 -08:00
|
|
|
return self
|
2015-10-09 19:53:38 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def remove(self, *mobjects_to_remove: Mobject):
|
2020-01-15 18:30:58 -08:00
|
|
|
self.mobjects = restructure_list_to_exclude_certain_family_members(
|
|
|
|
self.mobjects, mobjects_to_remove
|
|
|
|
)
|
2018-01-18 16:23:31 -08:00
|
|
|
return self
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def bring_to_front(self, *mobjects: Mobject):
|
2016-08-02 12:26:15 -07:00
|
|
|
self.add(*mobjects)
|
2015-10-12 19:39:46 -07:00
|
|
|
return self
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def bring_to_back(self, *mobjects: Mobject):
|
2016-08-02 12:26:15 -07:00
|
|
|
self.remove(*mobjects)
|
2018-01-17 21:32:50 -08:00
|
|
|
self.mobjects = list(mobjects) + self.mobjects
|
2015-10-12 19:39:46 -07:00
|
|
|
return self
|
|
|
|
|
2015-06-10 22:00:35 -07:00
|
|
|
def clear(self):
|
2015-10-29 13:45:28 -07:00
|
|
|
self.mobjects = []
|
2015-06-10 22:00:35 -07:00
|
|
|
return self
|
2015-03-30 17:51:26 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_mobjects(self) -> list[Mobject]:
|
2016-07-18 11:50:26 -07:00
|
|
|
return list(self.mobjects)
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_mobject_copies(self) -> list[Mobject]:
|
2016-07-18 11:50:26 -07:00
|
|
|
return [m.copy() for m in self.mobjects]
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def point_to_mobject(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
search_set: Iterable[Mobject] | None = None,
|
|
|
|
buff: float = 0
|
|
|
|
) -> Mobject | None:
|
2021-08-22 14:57:32 -07:00
|
|
|
"""
|
|
|
|
E.g. if clicking on the scene, this returns the top layer mobject
|
|
|
|
under a given point
|
|
|
|
"""
|
|
|
|
if search_set is None:
|
|
|
|
search_set = self.mobjects
|
|
|
|
for mobject in reversed(search_set):
|
|
|
|
if mobject.is_point_touching(point, buff=buff):
|
|
|
|
return mobject
|
|
|
|
return None
|
|
|
|
|
2022-04-20 21:48:58 -07:00
|
|
|
def get_group(self, *mobjects):
|
|
|
|
if all(isinstance(m, VMobject) for m in mobjects):
|
|
|
|
return VGroup(*mobjects)
|
|
|
|
else:
|
|
|
|
return Group(*mobjects)
|
|
|
|
|
|
|
|
def id_to_mobject(self, id_value):
|
|
|
|
for mob in self.mobjects:
|
|
|
|
for sm in mob.get_family():
|
|
|
|
if id(sm) == id_value:
|
|
|
|
return sm
|
|
|
|
return None
|
|
|
|
|
|
|
|
def ids_to_group(self, *id_values):
|
|
|
|
return self.get_group(*filter(
|
|
|
|
lambda x: x is not None,
|
|
|
|
map(self.id_to_mobject, id_values)
|
|
|
|
))
|
|
|
|
|
2021-01-05 22:37:28 -08:00
|
|
|
# Related to skipping
|
2022-02-14 21:22:18 +08:00
|
|
|
def update_skipping_status(self) -> None:
|
2021-01-05 22:37:28 -08:00
|
|
|
if self.start_at_animation_number is not None:
|
|
|
|
if self.num_plays == self.start_at_animation_number:
|
2021-12-07 10:04:28 -08:00
|
|
|
self.skip_time = self.time
|
|
|
|
if not self.original_skipping_status:
|
|
|
|
self.stop_skipping()
|
2021-01-05 22:37:28 -08:00
|
|
|
if self.end_at_animation_number is not None:
|
|
|
|
if self.num_plays >= self.end_at_animation_number:
|
|
|
|
raise EndSceneEarlyException()
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def stop_skipping(self) -> None:
|
2021-12-07 10:03:10 -08:00
|
|
|
self.virtual_animation_start_time = self.time
|
|
|
|
self.skip_animations = False
|
2021-01-05 22:37:28 -08:00
|
|
|
|
|
|
|
# Methods associated with running animations
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_time_progression(
|
|
|
|
self,
|
|
|
|
run_time: float,
|
|
|
|
n_iterations: int | None = None,
|
|
|
|
desc: str = "",
|
|
|
|
override_skip_animations: bool = False
|
|
|
|
) -> list[float] | np.ndarray | ProgressDisplay:
|
2019-01-15 12:19:09 -08:00
|
|
|
if self.skip_animations and not override_skip_animations:
|
2021-11-30 11:41:33 -08:00
|
|
|
return [run_time]
|
2018-02-19 17:24:17 -08:00
|
|
|
else:
|
2019-01-25 10:13:17 -08:00
|
|
|
step = 1 / self.camera.frame_rate
|
2018-02-20 17:50:39 -08:00
|
|
|
times = np.arange(0, run_time, step)
|
2021-11-30 11:41:33 -08:00
|
|
|
|
|
|
|
if self.file_writer.has_progress_display:
|
|
|
|
self.file_writer.set_progress_display_subdescription(desc)
|
|
|
|
return times
|
|
|
|
|
|
|
|
return ProgressDisplay(
|
2020-02-17 12:14:40 -08:00
|
|
|
times,
|
|
|
|
total=n_iterations,
|
2019-01-16 11:10:43 -08:00
|
|
|
leave=self.leave_progress_bars,
|
2021-11-30 11:41:33 -08:00
|
|
|
ascii=True if platform.system() == 'Windows' else None,
|
|
|
|
desc=desc,
|
2019-01-14 13:26:58 -08:00
|
|
|
)
|
2017-08-24 11:43:38 -07:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_run_time(self, animations: Iterable[Animation]) -> float:
|
2019-01-16 11:10:43 -08:00
|
|
|
return np.max([animation.run_time for animation in animations])
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_animation_time_progression(
|
|
|
|
self,
|
|
|
|
animations: Iterable[Animation]
|
|
|
|
) -> list[float] | np.ndarray | ProgressDisplay:
|
2019-01-16 11:10:43 -08:00
|
|
|
run_time = self.get_run_time(animations)
|
2021-11-30 11:41:33 -08:00
|
|
|
description = f"{self.num_plays} {animations[0]}"
|
|
|
|
if len(animations) > 1:
|
|
|
|
description += ", etc."
|
|
|
|
time_progression = self.get_time_progression(run_time, desc=description)
|
2016-02-27 12:44:52 -08:00
|
|
|
return time_progression
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def get_wait_time_progression(
|
|
|
|
self,
|
|
|
|
duration: float,
|
|
|
|
stop_condition: Callable[[], bool] | None = None
|
|
|
|
) -> list[float] | np.ndarray | ProgressDisplay:
|
2021-11-30 11:41:33 -08:00
|
|
|
kw = {"desc": f"{self.num_plays} Waiting"}
|
2021-01-05 22:37:28 -08:00
|
|
|
if stop_condition is not None:
|
2021-11-30 11:41:33 -08:00
|
|
|
kw["n_iterations"] = -1 # So it doesn't show % progress
|
|
|
|
kw["override_skip_animations"] = True
|
|
|
|
return self.get_time_progression(duration, **kw)
|
2021-01-05 22:37:28 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def anims_from_play_args(self, *args, **kwargs) -> list[Animation]:
|
2016-07-28 11:16:07 -07:00
|
|
|
"""
|
2018-01-20 11:19:12 -08:00
|
|
|
Each arg can either be an animation, or a mobject method
|
|
|
|
followed by that methods arguments (and potentially follow
|
|
|
|
by a dict of kwargs for that method).
|
2017-10-05 21:03:30 -05:00
|
|
|
This animation list is built by going through the args list,
|
|
|
|
and each animation is simply added, but when a mobject method
|
|
|
|
s hit, a MoveToTarget animation is built using the args that
|
|
|
|
follow up until either another animation is hit, another method
|
2016-07-28 11:16:07 -07:00
|
|
|
is hit, or the args list runs out.
|
|
|
|
"""
|
|
|
|
animations = []
|
2016-09-06 14:17:39 -07:00
|
|
|
state = {
|
2018-04-06 13:58:59 -07:00
|
|
|
"curr_method": None,
|
|
|
|
"last_method": None,
|
|
|
|
"method_args": [],
|
2016-07-28 11:16:07 -07:00
|
|
|
}
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2016-09-06 14:17:39 -07:00
|
|
|
def compile_method(state):
|
|
|
|
if state["curr_method"] is None:
|
2016-07-28 11:16:07 -07:00
|
|
|
return
|
2018-06-02 08:59:26 -04:00
|
|
|
mobject = state["curr_method"].__self__
|
|
|
|
if state["last_method"] and state["last_method"].__self__ is mobject:
|
2016-09-06 14:17:39 -07:00
|
|
|
animations.pop()
|
2018-04-06 13:58:59 -07:00
|
|
|
# method should already have target then.
|
2016-09-06 14:17:39 -07:00
|
|
|
else:
|
2018-02-26 19:07:57 -08:00
|
|
|
mobject.generate_target()
|
2018-01-20 11:19:12 -08:00
|
|
|
#
|
2018-01-20 11:45:47 -08:00
|
|
|
if len(state["method_args"]) > 0 and isinstance(state["method_args"][-1], dict):
|
2018-01-20 11:19:12 -08:00
|
|
|
method_kwargs = state["method_args"].pop()
|
|
|
|
else:
|
|
|
|
method_kwargs = {}
|
2018-06-02 08:59:26 -04:00
|
|
|
state["curr_method"].__func__(
|
2018-04-06 13:58:59 -07:00
|
|
|
mobject.target,
|
2018-01-20 11:19:12 -08:00
|
|
|
*state["method_args"],
|
|
|
|
**method_kwargs
|
2016-09-06 14:17:39 -07:00
|
|
|
)
|
|
|
|
animations.append(MoveToTarget(mobject))
|
|
|
|
state["last_method"] = state["curr_method"]
|
|
|
|
state["curr_method"] = None
|
|
|
|
state["method_args"] = []
|
2016-09-06 16:48:04 -07:00
|
|
|
|
2016-07-28 11:16:07 -07:00
|
|
|
for arg in args:
|
2021-02-10 07:43:46 -06:00
|
|
|
if inspect.ismethod(arg):
|
2016-09-06 14:17:39 -07:00
|
|
|
compile_method(state)
|
|
|
|
state["curr_method"] = arg
|
|
|
|
elif state["curr_method"] is not None:
|
|
|
|
state["method_args"].append(arg)
|
2016-09-07 22:04:24 -07:00
|
|
|
elif isinstance(arg, Mobject):
|
|
|
|
raise Exception("""
|
2017-10-05 21:03:30 -05:00
|
|
|
I think you may have invoked a method
|
2016-09-07 22:04:24 -07:00
|
|
|
you meant to pass in as a Scene.play argument
|
|
|
|
""")
|
2016-07-28 11:16:07 -07:00
|
|
|
else:
|
2021-02-10 07:43:46 -06:00
|
|
|
try:
|
|
|
|
anim = prepare_animation(arg)
|
|
|
|
except TypeError:
|
|
|
|
raise TypeError(f"Unexpected argument {arg} passed to Scene.play()")
|
|
|
|
|
|
|
|
compile_method(state)
|
|
|
|
animations.append(anim)
|
2016-09-06 14:17:39 -07:00
|
|
|
compile_method(state)
|
2019-02-08 12:51:21 -08:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2016-07-28 11:16:07 -07:00
|
|
|
return animations
|
2016-02-27 18:50:33 -08:00
|
|
|
|
2019-01-24 22:24:01 -08:00
|
|
|
def handle_play_like_call(func):
|
2020-08-16 11:59:07 +02:00
|
|
|
@wraps(func)
|
2019-01-24 22:24:01 -08:00
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
self.update_skipping_status()
|
2020-02-18 22:30:43 -08:00
|
|
|
should_write = not self.skip_animations
|
|
|
|
if should_write:
|
2020-02-11 19:51:19 -08:00
|
|
|
self.file_writer.begin_animation()
|
2020-02-18 22:30:43 -08:00
|
|
|
|
|
|
|
if self.window:
|
|
|
|
self.real_animation_start_time = time.time()
|
|
|
|
self.virtual_animation_start_time = self.time
|
|
|
|
|
2022-04-14 16:27:58 -07:00
|
|
|
self.refresh_static_mobjects()
|
2020-02-18 22:30:43 -08:00
|
|
|
func(self, *args, **kwargs)
|
|
|
|
|
|
|
|
if should_write:
|
2020-02-11 19:51:19 -08:00
|
|
|
self.file_writer.end_animation()
|
2020-02-18 22:30:43 -08:00
|
|
|
|
2019-01-24 22:24:01 -08:00
|
|
|
self.num_plays += 1
|
|
|
|
return wrapper
|
|
|
|
|
2022-04-14 16:27:58 -07:00
|
|
|
def refresh_static_mobjects(self) -> None:
|
|
|
|
self.camera.refresh_static_mobjects()
|
2022-02-13 15:16:16 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def begin_animations(self, animations: Iterable[Animation]) -> None:
|
2018-02-19 16:50:58 -08:00
|
|
|
for animation in animations:
|
2019-02-11 20:53:20 -08:00
|
|
|
animation.begin()
|
2018-08-12 12:17:32 -07:00
|
|
|
# Anything animated that's not already in the
|
2020-02-21 10:56:40 -08:00
|
|
|
# scene gets added to the scene. Note, for
|
|
|
|
# animated mobjects that are in the family of
|
|
|
|
# those on screen, this can result in a restructuring
|
|
|
|
# of the scene.mobjects list, which is usually desired.
|
2021-01-05 22:37:28 -08:00
|
|
|
if animation.mobject not in self.mobjects:
|
|
|
|
self.add(animation.mobject)
|
2019-02-08 11:00:04 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def progress_through_animations(self, animations: Iterable[Animation]) -> None:
|
2019-02-08 12:51:21 -08:00
|
|
|
last_t = 0
|
2017-08-24 11:43:38 -07:00
|
|
|
for t in self.get_animation_time_progression(animations):
|
2019-02-08 12:51:21 -08:00
|
|
|
dt = t - last_t
|
|
|
|
last_t = t
|
2015-04-03 16:41:25 -07:00
|
|
|
for animation in animations:
|
2019-02-08 12:32:24 -08:00
|
|
|
animation.update_mobjects(dt)
|
2019-02-08 12:51:21 -08:00
|
|
|
alpha = t / animation.run_time
|
|
|
|
animation.interpolate(alpha)
|
2020-02-14 11:55:07 -08:00
|
|
|
self.update_frame(dt)
|
|
|
|
self.emit_frame()
|
2019-02-08 11:00:04 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def finish_animations(self, animations: Iterable[Animation]) -> None:
|
2019-02-08 11:00:04 -08:00
|
|
|
for animation in animations:
|
|
|
|
animation.finish()
|
2019-02-08 11:57:27 -08:00
|
|
|
animation.clean_up_from_scene(self)
|
2018-02-19 17:24:17 -08:00
|
|
|
if self.skip_animations:
|
2019-02-15 20:05:16 -08:00
|
|
|
self.update_mobjects(self.get_run_time(animations))
|
2018-02-19 17:24:17 -08:00
|
|
|
else:
|
2019-02-15 20:05:16 -08:00
|
|
|
self.update_mobjects(0)
|
2018-11-01 11:23:34 +03:00
|
|
|
|
2019-02-08 12:51:21 -08:00
|
|
|
@handle_play_like_call
|
2022-02-14 21:22:18 +08:00
|
|
|
def play(self, *args, **kwargs) -> None:
|
2019-02-08 12:51:21 -08:00
|
|
|
if len(args) == 0:
|
2021-10-16 13:04:52 +08:00
|
|
|
log.warning("Called Scene.play with no animations")
|
2019-02-08 12:51:21 -08:00
|
|
|
return
|
2020-02-11 19:51:19 -08:00
|
|
|
animations = self.anims_from_play_args(*args, **kwargs)
|
2019-02-08 15:26:30 -08:00
|
|
|
self.begin_animations(animations)
|
2019-02-08 12:51:21 -08:00
|
|
|
self.progress_through_animations(animations)
|
|
|
|
self.finish_animations(animations)
|
2016-07-19 11:07:26 -07:00
|
|
|
|
2019-01-10 17:06:22 -08:00
|
|
|
@handle_play_like_call
|
2022-02-14 21:22:18 +08:00
|
|
|
def wait(
|
|
|
|
self,
|
|
|
|
duration: float = DEFAULT_WAIT_TIME,
|
|
|
|
stop_condition: Callable[[], bool] = None,
|
|
|
|
note: str = None,
|
|
|
|
ignore_presenter_mode: bool = False
|
|
|
|
):
|
2022-02-13 15:16:16 -08:00
|
|
|
if note:
|
|
|
|
log.info(note)
|
2019-02-15 20:05:16 -08:00
|
|
|
self.update_mobjects(dt=0) # Any problems with this?
|
2022-02-13 15:16:16 -08:00
|
|
|
if self.presenter_mode and not self.skip_animations and not ignore_presenter_mode:
|
|
|
|
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():
|
|
|
|
break
|
2022-04-14 16:27:58 -07:00
|
|
|
self.refresh_static_mobjects()
|
2015-06-09 11:26:12 -07:00
|
|
|
return self
|
2015-03-22 16:15:29 -06:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def wait_until(
|
|
|
|
self,
|
|
|
|
stop_condition: Callable[[], bool],
|
|
|
|
max_time: float = 60
|
|
|
|
):
|
2019-01-14 13:26:58 -08:00
|
|
|
self.wait(max_time, stop_condition=stop_condition)
|
2018-01-29 21:29:36 -08:00
|
|
|
|
2017-03-20 14:37:51 -07:00
|
|
|
def force_skipping(self):
|
|
|
|
self.original_skipping_status = self.skip_animations
|
|
|
|
self.skip_animations = True
|
|
|
|
return self
|
|
|
|
|
|
|
|
def revert_to_original_skipping_status(self):
|
|
|
|
if hasattr(self, "original_skipping_status"):
|
|
|
|
self.skip_animations = self.original_skipping_status
|
|
|
|
return self
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def add_sound(
|
|
|
|
self,
|
|
|
|
sound_file: str,
|
|
|
|
time_offset: float = 0,
|
|
|
|
gain: float | None = None,
|
|
|
|
gain_to_background: float | None = None
|
|
|
|
):
|
2019-09-10 13:26:30 -07:00
|
|
|
if self.skip_animations:
|
|
|
|
return
|
2019-01-24 22:24:01 -08:00
|
|
|
time = self.get_time() + time_offset
|
2022-02-14 21:22:18 +08:00
|
|
|
self.file_writer.add_sound(sound_file, time, gain, gain_to_background)
|
2019-01-24 22:24:01 -08:00
|
|
|
|
2020-02-22 13:20:22 -08:00
|
|
|
# Helpers for interactive development
|
2022-02-14 21:22:18 +08:00
|
|
|
def save_state(self) -> None:
|
2022-04-20 21:49:38 -07:00
|
|
|
self.saved_state = [
|
|
|
|
(mob, mob.copy())
|
|
|
|
for mob in self.mobjects
|
|
|
|
]
|
2020-02-22 13:20:22 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def restore(self) -> None:
|
2020-02-22 13:20:22 -08:00
|
|
|
if not hasattr(self, "saved_state"):
|
|
|
|
raise Exception("Trying to restore scene without having saved")
|
2022-04-20 21:49:38 -07:00
|
|
|
self.mobjects = []
|
|
|
|
for mob, mob_state in self.saved_state:
|
|
|
|
mob.become(mob_state)
|
|
|
|
self.mobjects.append(mob)
|
2020-02-22 13:20:22 -08:00
|
|
|
|
2020-02-11 19:51:19 -08:00
|
|
|
# Event handling
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_mouse_motion(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
d_point: np.ndarray
|
|
|
|
) -> None:
|
2020-02-14 15:30:44 -08:00
|
|
|
self.mouse_point.move_to(point)
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"point": point, "d_point": d_point}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.MouseMotionEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2021-01-06 12:48:58 -08:00
|
|
|
frame = self.camera.frame
|
2022-04-14 14:36:17 -07:00
|
|
|
# Handle perspective changes
|
2021-01-06 12:48:58 -08:00
|
|
|
if self.window.is_key_pressed(ord("d")):
|
2022-03-22 10:36:48 -07:00
|
|
|
frame.increment_theta(-self.pan_sensitivity * d_point[0])
|
|
|
|
frame.increment_phi(self.pan_sensitivity * d_point[1])
|
2022-04-14 14:36:17 -07:00
|
|
|
# Handle frame movements
|
2021-01-18 16:39:29 -08:00
|
|
|
elif self.window.is_key_pressed(ord("s")):
|
2021-01-19 14:12:25 -08:00
|
|
|
shift = -d_point
|
|
|
|
shift[0] *= frame.get_width() / 2
|
|
|
|
shift[1] *= frame.get_height() / 2
|
2021-01-18 16:39:29 -08:00
|
|
|
transform = frame.get_inverse_camera_rotation_matrix()
|
2021-01-19 14:12:25 -08:00
|
|
|
shift = np.dot(np.transpose(transform), shift)
|
|
|
|
frame.shift(shift)
|
2021-01-18 16:39:29 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_mouse_drag(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
d_point: np.ndarray,
|
|
|
|
buttons: int,
|
|
|
|
modifiers: int
|
|
|
|
) -> None:
|
2021-01-18 16:39:29 -08:00
|
|
|
self.mouse_drag_point.move_to(point)
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"point": point, "d_point": d_point, "buttons": buttons, "modifiers": modifiers}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.MouseDragEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2021-01-31 16:05:55 +05:30
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_mouse_press(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
button: int,
|
|
|
|
mods: int
|
|
|
|
) -> None:
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"point": point, "button": button, "mods": mods}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.MousePressEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_mouse_release(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
button: int,
|
|
|
|
mods: int
|
|
|
|
) -> None:
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"point": point, "button": button, "mods": mods}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.MouseReleaseEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_mouse_scroll(
|
|
|
|
self,
|
|
|
|
point: np.ndarray,
|
|
|
|
offset: np.ndarray
|
|
|
|
) -> None:
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"point": point, "offset": offset}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.MouseScrollEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2021-01-08 22:26:14 -08:00
|
|
|
frame = self.camera.frame
|
2021-01-06 12:48:58 -08:00
|
|
|
if self.window.is_key_pressed(ord("z")):
|
2020-02-14 16:26:49 -08:00
|
|
|
factor = 1 + np.arctan(10 * offset[1])
|
2021-07-14 13:56:20 +05:30
|
|
|
frame.scale(1/factor, about_point=point)
|
2021-01-19 14:12:25 -08:00
|
|
|
else:
|
|
|
|
transform = frame.get_inverse_camera_rotation_matrix()
|
|
|
|
shift = np.dot(np.transpose(transform), offset)
|
|
|
|
frame.shift(-20.0 * shift)
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_key_release(
|
|
|
|
self,
|
|
|
|
symbol: int,
|
|
|
|
modifiers: int
|
|
|
|
) -> None:
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"symbol": symbol, "modifiers": modifiers}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.KeyReleaseEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_key_press(
|
|
|
|
self,
|
|
|
|
symbol: int,
|
|
|
|
modifiers: int
|
|
|
|
) -> None:
|
2021-01-16 10:21:42 +08:00
|
|
|
try:
|
|
|
|
char = chr(symbol)
|
|
|
|
except OverflowError:
|
2021-10-07 17:37:10 +08:00
|
|
|
log.warning("The value of the pressed key is too large.")
|
2021-01-16 10:21:42 +08:00
|
|
|
return
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2021-02-02 16:04:50 +05:30
|
|
|
event_data = {"symbol": symbol, "modifiers": modifiers}
|
|
|
|
propagate_event = EVENT_DISPATCHER.dispatch(EventType.KeyPressEvent, **event_data)
|
|
|
|
if propagate_event is not None and propagate_event is False:
|
|
|
|
return
|
2021-01-28 14:02:43 +05:30
|
|
|
|
2021-01-16 10:21:42 +08:00
|
|
|
if char == "r":
|
2020-06-01 16:21:18 -07:00
|
|
|
self.camera.frame.to_default_state()
|
2021-01-16 10:21:42 +08:00
|
|
|
elif char == "q":
|
2020-02-14 16:26:49 -08:00
|
|
|
self.quit_interaction = True
|
2022-02-14 07:56:26 -08:00
|
|
|
elif char == " " or symbol == 65363: # Space or right arrow
|
2022-02-13 15:16:16 -08:00
|
|
|
self.hold_on_wait = False
|
2022-02-15 10:10:57 -08:00
|
|
|
elif char == "e" and modifiers == 3: # ctrl + shift + e
|
2022-02-13 15:16:16 -08:00
|
|
|
self.embed(close_scene_on_exit=False)
|
2020-02-11 19:51:19 -08:00
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_resize(self, width: int, height: int) -> None:
|
2020-02-11 19:51:19 -08:00
|
|
|
self.camera.reset_pixel_shape(width, height)
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_show(self) -> None:
|
2020-02-11 19:51:19 -08:00
|
|
|
pass
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_hide(self) -> None:
|
2020-02-11 19:51:19 -08:00
|
|
|
pass
|
|
|
|
|
2022-02-14 21:22:18 +08:00
|
|
|
def on_close(self) -> None:
|
2020-02-11 19:51:19 -08:00
|
|
|
pass
|
|
|
|
|
2018-04-06 13:58:59 -07:00
|
|
|
|
2018-02-19 17:24:17 -08:00
|
|
|
class EndSceneEarlyException(Exception):
|
|
|
|
pass
|