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
if n_spaces is None:
n_spaces = get_indent(lines[prev_line_num])
lines.insert(prev_line_num + 1, " " * n_spaces + "self.embed()\n")
alt_file = file_name.replace(".py", "_inserted_embed.py")
with open(alt_file, 'w') as fp:
fp.writelines(lines)
new_lines = list(lines)
new_lines.insert(prev_line_num + 1, " " * n_spaces + "self.embed()\n")
with open(file_name, 'w') as fp:
fp.writelines(new_lines)
try:
yield alt_file
yield file_name
finally:
os.remove(alt_file)
with open(file_name, 'w') as fp:
fp.writelines(lines)
def get_custom_config():

View file

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

View file

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

View file

@ -1,7 +1,6 @@
from __future__ import annotations
import hashlib
import itertools as it
import os
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 RoundedRectangle
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.images import get_full_vector_image_path
from manimlib.utils.iterables import hash_obj

View file

@ -398,10 +398,6 @@ class InteractiveScene(Scene):
self.ungroup_selection()
elif char == "t" and modifiers == COMMAND_MODIFIER:
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:
self.save_selection_to_file()
elif symbol in ARROW_SYMBOLS:

View file

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