Merge pull request #1797 from 3b1b/video-work

Video work
This commit is contained in:
Grant Sanderson 2022-04-23 10:18:25 -07:00 committed by GitHub
commit 304cf88451
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 32 deletions

View file

@ -243,15 +243,15 @@ def insert_embed_line(file_name: str, scene_name: str, line_marker: str):
# Insert and write new file # Insert and write new file
if n_spaces is None: if n_spaces is None:
n_spaces = get_indent(lines[prev_line_num]) n_spaces = get_indent(lines[prev_line_num])
lines.insert(prev_line_num + 1, " " * n_spaces + "self.embed()\n") new_lines = list(lines)
alt_file = file_name.replace(".py", "_inserted_embed.py") new_lines.insert(prev_line_num + 1, " " * n_spaces + "self.embed()\n")
with open(alt_file, 'w') as fp: with open(file_name, 'w') as fp:
fp.writelines(lines) fp.writelines(new_lines)
try: try:
yield alt_file yield file_name
finally: finally:
os.remove(alt_file) with open(file_name, 'w') as fp:
fp.writelines(lines)
def get_custom_config(): def get_custom_config():

View file

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
from isosurfaces import plot_isoline from isosurfaces import plot_isoline
import numpy as np
from manimlib.constants import FRAME_X_RADIUS, FRAME_Y_RADIUS from manimlib.constants import FRAME_X_RADIUS, FRAME_Y_RADIUS
from manimlib.constants import YELLOW from manimlib.constants import YELLOW

View file

@ -500,28 +500,31 @@ class Mobject(object):
self.become(pickle.loads(data)) self.become(pickle.loads(data))
return self return self
def deepcopy(self):
try:
# Often faster than deepcopy
return pickle.loads(pickle.dumps(self))
except AttributeError:
return copy.deepcopy(self)
@stash_mobject_pointers @stash_mobject_pointers
def copy(self, deep: bool = False): def copy(self, deep: bool = False):
if deep: if deep:
try: return self.deepcopy()
# Often faster than deepcopy
return pickle.loads(pickle.dumps(self))
except AttributeError:
return copy.deepcopy(self)
result = copy.copy(self) result = copy.copy(self)
# The line above is only a shallow copy, so the internal # The line above is only a shallow copy, so the internal
# data which are numpyu arrays or other mobjects still # data which are numpyu arrays or other mobjects still
# need to be further copied. # need to be further copied.
result.data = dict(self.data) result.data = {
for key in result.data: key: np.array(value)
result.data[key] = result.data[key].copy() for key, value in self.data.items()
}
result.uniforms = dict(self.uniforms) result.uniforms = {
for key in result.uniforms: key: np.array(value)
if isinstance(result.uniforms[key], np.ndarray): for key, value in self.uniforms.items()
result.uniforms[key] = result.uniforms[key].copy() }
result.submobjects = [] result.submobjects = []
result.add(*(sm.copy() for sm in self.submobjects)) result.add(*(sm.copy() for sm in self.submobjects))
@ -529,17 +532,17 @@ class Mobject(object):
family = self.get_family() family = self.get_family()
for attr, value in list(self.__dict__.items()): for attr, value in list(self.__dict__.items()):
if isinstance(value, Mobject) and value in family and value is not self: if isinstance(value, Mobject) and value is not self:
setattr(result, attr, result.family[self.family.index(value)]) if value in family:
setattr(result, attr, result.family[self.family.index(value)])
else:
setattr(result, attr, value.copy())
if isinstance(value, np.ndarray): if isinstance(value, np.ndarray):
setattr(result, attr, value.copy()) setattr(result, attr, value.copy())
if isinstance(value, ShaderWrapper): if isinstance(value, ShaderWrapper):
setattr(result, attr, value.copy()) setattr(result, attr, value.copy())
return result return result
def deepcopy(self):
return self.copy(deep=True)
def generate_target(self, use_deepcopy: bool = False): def generate_target(self, use_deepcopy: bool = False):
self.target = self.copy(deep=use_deepcopy) self.target = self.copy(deep=use_deepcopy)
self.target.saved_state = self.saved_state self.target.saved_state = self.saved_state

View file

@ -1,7 +1,6 @@
from __future__ import annotations from __future__ import annotations
import hashlib import hashlib
import itertools as it
import os import os
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
@ -17,7 +16,6 @@ from manimlib.mobject.geometry import Polyline
from manimlib.mobject.geometry import Rectangle from manimlib.mobject.geometry import Rectangle
from manimlib.mobject.geometry import RoundedRectangle from manimlib.mobject.geometry import RoundedRectangle
from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.utils.config_ops import digest_config
from manimlib.utils.directories import get_mobject_data_dir from manimlib.utils.directories import get_mobject_data_dir
from manimlib.utils.images import get_full_vector_image_path from manimlib.utils.images import get_full_vector_image_path
from manimlib.utils.iterables import hash_obj from manimlib.utils.iterables import hash_obj

View file

@ -398,10 +398,6 @@ class InteractiveScene(Scene):
self.ungroup_selection() self.ungroup_selection()
elif char == "t" and modifiers == COMMAND_MODIFIER: elif char == "t" and modifiers == COMMAND_MODIFIER:
self.toggle_selection_mode() self.toggle_selection_mode()
elif char == "z" and modifiers == COMMAND_MODIFIER:
self.undo()
elif char == "z" and modifiers == COMMAND_MODIFIER | SHIFT_MODIFIER:
self.redo()
elif char == "s" and modifiers == COMMAND_MODIFIER: elif char == "s" and modifiers == COMMAND_MODIFIER:
self.save_selection_to_file() self.save_selection_to_file()
elif symbol in ARROW_SYMBOLS: elif symbol in ARROW_SYMBOLS:

View file

@ -2,7 +2,6 @@ from __future__ import annotations
from functools import wraps from functools import wraps
import inspect import inspect
import itertools as it
import os import os
import platform import platform
import random import random
@ -17,6 +16,7 @@ from manimlib.camera.camera import Camera
from manimlib.constants import ARROW_SYMBOLS from manimlib.constants import ARROW_SYMBOLS
from manimlib.constants import DEFAULT_WAIT_TIME from manimlib.constants import DEFAULT_WAIT_TIME
from manimlib.constants import COMMAND_MODIFIER from manimlib.constants import COMMAND_MODIFIER
from manimlib.constants import SHIFT_MODIFIER
from manimlib.event_handler import EVENT_DISPATCHER from manimlib.event_handler import EVENT_DISPATCHER
from manimlib.event_handler.event_type import EventType from manimlib.event_handler.event_type import EventType
from manimlib.logger import log from manimlib.logger import log
@ -785,6 +785,10 @@ class Scene(object):
if char == RESET_FRAME_KEY: if char == RESET_FRAME_KEY:
self.camera.frame.to_default_state() self.camera.frame.to_default_state()
elif char == "z" and modifiers == COMMAND_MODIFIER:
self.undo()
elif char == "z" and modifiers == COMMAND_MODIFIER | SHIFT_MODIFIER:
self.redo()
# command + q # command + q
elif char == QUIT_KEY and modifiers == COMMAND_MODIFIER: elif char == QUIT_KEY and modifiers == COMMAND_MODIFIER:
self.quit_interaction = True self.quit_interaction = True