Changes to make reduce the time of from manimlib import *

This commit is contained in:
Grant Sanderson 2021-02-11 12:21:06 -08:00
parent e7240547fb
commit e1e7b1e6c1
7 changed files with 74 additions and 113 deletions

View file

@ -16,15 +16,11 @@ from manimlib.animation.update import *
from manimlib.camera.camera import * from manimlib.camera.camera import *
# This must be called before manimlib.mobject.interactive
from manimlib.window import *
from manimlib.mobject.coordinate_systems import * from manimlib.mobject.coordinate_systems import *
from manimlib.mobject.changing import * from manimlib.mobject.changing import *
from manimlib.mobject.frame import * from manimlib.mobject.frame import *
from manimlib.mobject.functions import * from manimlib.mobject.functions import *
from manimlib.mobject.geometry import * from manimlib.mobject.geometry import *
from manimlib.mobject.interactive import *
from manimlib.mobject.matrix import * from manimlib.mobject.matrix import *
from manimlib.mobject.mobject import * from manimlib.mobject.mobject import *
from manimlib.mobject.number_line import * from manimlib.mobject.number_line import *
@ -46,18 +42,8 @@ from manimlib.mobject.mobject_update_utils import *
from manimlib.mobject.value_tracker import * from manimlib.mobject.value_tracker import *
from manimlib.mobject.vector_field import * from manimlib.mobject.vector_field import *
from manimlib.once_useful_constructs.arithmetic import *
from manimlib.once_useful_constructs.combinatorics import *
from manimlib.once_useful_constructs.complex_transformation_scene import *
from manimlib.once_useful_constructs.counting import *
from manimlib.once_useful_constructs.fractals import *
from manimlib.once_useful_constructs.graph_theory import *
from manimlib.once_useful_constructs.light import *
from manimlib.scene.scene import * from manimlib.scene.scene import *
from manimlib.scene.sample_space_scene import *
from manimlib.scene.three_d_scene import * from manimlib.scene.three_d_scene import *
from manimlib.scene.vector_space_scene import *
from manimlib.utils.bezier import * from manimlib.utils.bezier import *
from manimlib.utils.color import * from manimlib.utils.color import *

View file

@ -1,6 +1,7 @@
from copy import deepcopy from copy import deepcopy
from manimlib.mobject.mobject import Mobject, _AnimationBuilder from manimlib.mobject.mobject import _AnimationBuilder
from manimlib.mobject.mobject import Mobject
from manimlib.utils.config_ops import digest_config from manimlib.utils.config_ops import digest_config
from manimlib.utils.rate_functions import smooth from manimlib.utils.rate_functions import smooth
from manimlib.utils.simple_functions import clip from manimlib.utils.simple_functions import clip

View file

@ -71,63 +71,68 @@ BOLD = "BOLD"
DEFAULT_STROKE_WIDTH = 4 DEFAULT_STROKE_WIDTH = 4
# Colors # Colors
COLOR_MAP = { BLUE_E = "#1C758A"
"BLUE_E": "#1C758A", BLUE_D = "#29ABCA"
"BLUE_D": "#29ABCA", BLUE_C = "#58C4DD"
"BLUE_C": "#58C4DD", BLUE_B = "#9CDCEB"
"BLUE_B": "#9CDCEB", BLUE_A = "#C7E9F1"
"BLUE_A": "#C7E9F1", TEAL_E = "#49A88F"
"TEAL_E": "#49A88F", TEAL_D = "#55C1A7"
"TEAL_D": "#55C1A7", TEAL_C = "#5CD0B3"
"TEAL_C": "#5CD0B3", TEAL_B = "#76DDC0"
"TEAL_B": "#76DDC0", TEAL_A = "#ACEAD7"
"TEAL_A": "#ACEAD7", GREEN_E = "#699C52"
"GREEN_E": "#699C52", GREEN_D = "#77B05D"
"GREEN_D": "#77B05D", GREEN_C = "#83C167"
"GREEN_C": "#83C167", GREEN_B = "#A6CF8C"
"GREEN_B": "#A6CF8C", GREEN_A = "#C9E2AE"
"GREEN_A": "#C9E2AE", YELLOW_E = "#E8C11C"
"YELLOW_E": "#E8C11C", YELLOW_D = "#F4D345"
"YELLOW_D": "#F4D345", YELLOW_C = "#FFFF00"
"YELLOW_C": "#FFFF00", YELLOW_B = "#FFEA94"
"YELLOW_B": "#FFEA94", YELLOW_A = "#FFF1B6"
"YELLOW_A": "#FFF1B6", GOLD_E = "#C78D46"
"GOLD_E": "#C78D46", GOLD_D = "#E1A158"
"GOLD_D": "#E1A158", GOLD_C = "#F0AC5F"
"GOLD_C": "#F0AC5F", GOLD_B = "#F9B775"
"GOLD_B": "#F9B775", GOLD_A = "#F7C797"
"GOLD_A": "#F7C797", RED_E = "#CF5044"
"RED_E": "#CF5044", RED_D = "#E65A4C"
"RED_D": "#E65A4C", RED_C = "#FC6255"
"RED_C": "#FC6255", RED_B = "#FF8080"
"RED_B": "#FF8080", RED_A = "#F7A1A3"
"RED_A": "#F7A1A3", MAROON_E = "#94424F"
"MAROON_E": "#94424F", MAROON_D = "#A24D61"
"MAROON_D": "#A24D61", MAROON_C = "#C55F73"
"MAROON_C": "#C55F73", MAROON_B = "#EC92AB"
"MAROON_B": "#EC92AB", MAROON_A = "#ECABC1"
"MAROON_A": "#ECABC1", PURPLE_E = "#644172"
"PURPLE_E": "#644172", PURPLE_D = "#715582"
"PURPLE_D": "#715582", PURPLE_C = "#9A72AC"
"PURPLE_C": "#9A72AC", PURPLE_B = "#B189C6"
"PURPLE_B": "#B189C6", PURPLE_A = "#CAA3E8"
"PURPLE_A": "#CAA3E8", GREY_E = "#222222"
"GREY_E": "#222222", GREY_D = "#444444"
"GREY_D": "#444444", GREY_C = "#888888"
"GREY_C": "#888888", GREY_B = "#BBBBBB"
"GREY_B": "#BBBBBB", GREY_A = "#DDDDDD"
"GREY_A": "#DDDDDD", WHITE = "#FFFFFF"
"WHITE": "#FFFFFF", BLACK = "#000000"
"BLACK": "#000000", GREY_BROWN = "#736357"
"GREY_BROWN": "#736357", DARK_BROWN = "#8B4513"
"DARK_BROWN": "#8B4513", LIGHT_BROWN = "#CD853F"
"LIGHT_BROWN": "#CD853F", PINK = "#D147BD"
"PINK": "#D147BD", LIGHT_PINK = "#DC75CD"
"LIGHT_PINK": "#DC75CD", GREEN_SCREEN = "#00FF00"
"GREEN_SCREEN": "#00FF00", ORANGE = "#FF862F"
"ORANGE": "#FF862F",
} # Abbreviated names for the "median" colors
PALETTE = list(COLOR_MAP.values()) BLUE = BLUE_C = "#58C4DD"
locals().update(COLOR_MAP) TEAL = TEAL_C = "#5CD0B3"
for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]: GREEN = GREEN_C = "#83C167"
locals()[name.replace("_C", "")] = locals()[name] YELLOW = YELLOW_C = "#FFFF00"
GOLD = GOLD_C = "#F0AC5F"
RED = RED_C = "#FC6255"
MAROON = MAROON_C = "#C55F73"
PURPLE = PURPLE_C = "#9A72AC"
GREY = GREY_C = "#888888"

View file

@ -9,7 +9,6 @@ from tqdm import tqdm as ProgressDisplay
import numpy as np import numpy as np
import time import time
import moderngl import moderngl
from IPython.terminal.embed import InteractiveShellEmbed
from manimlib.animation.animation import prepare_animation from manimlib.animation.animation import prepare_animation
from manimlib.animation.transform import MoveToTarget from manimlib.animation.transform import MoveToTarget
@ -23,7 +22,6 @@ from manimlib.utils.family_ops import extract_mobject_family_members
from manimlib.utils.family_ops import restructure_list_to_exclude_certain_family_members from manimlib.utils.family_ops import restructure_list_to_exclude_certain_family_members
from manimlib.event_handler.event_type import EventType from manimlib.event_handler.event_type import EventType
from manimlib.event_handler import EVENT_DISPATCHER from manimlib.event_handler import EVENT_DISPATCHER
from manimlib.window import Window
class Scene(object): class Scene(object):
@ -45,6 +43,7 @@ class Scene(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
digest_config(self, kwargs) digest_config(self, kwargs)
if self.preview: if self.preview:
from manimlib.window import Window
self.window = Window(scene=self, **self.window_config) self.window = Window(scene=self, **self.window_config)
self.camera_config["ctx"] = self.window.ctx self.camera_config["ctx"] = self.window.ctx
else: else:
@ -119,7 +118,8 @@ class Scene(object):
self.stop_skipping() self.stop_skipping()
self.linger_after_completion = False self.linger_after_completion = False
self.update_frame() self.update_frame()
from IPython.terminal.embed import InteractiveShellEmbed
shell = InteractiveShellEmbed() shell = InteractiveShellEmbed()
# Have the frame update after each command # Have the frame update after each command
shell.events.register('post_run_cell', lambda *a, **kw: self.update_frame()) shell.events.register('post_run_cell', lambda *a, **kw: self.update_frame())

View file

@ -2,9 +2,7 @@ import random
from colour import Color from colour import Color
import numpy as np import numpy as np
from matplotlib.cm import get_cmap
from manimlib.constants import PALETTE
from manimlib.constants import WHITE from manimlib.constants import WHITE
from manimlib.utils.bezier import interpolate from manimlib.utils.bezier import interpolate
from manimlib.utils.simple_functions import clip_in_place from manimlib.utils.simple_functions import clip_in_place
@ -102,7 +100,7 @@ def random_bright_color():
def random_color(): def random_color():
return random.choice(PALETTE) return Color(rgb=(random.random() for i in range(3)))
def get_shaded_rgb(rgb, point, unit_normal_vect, light_source): def get_shaded_rgb(rgb, point, unit_normal_vect, light_source):
@ -116,6 +114,8 @@ def get_shaded_rgb(rgb, point, unit_normal_vect, light_source):
def get_colormap_list(map_name="viridis", n_colors=9): def get_colormap_list(map_name="viridis", n_colors=9):
from matplotlib.cm import get_cmap
rgbs = get_cmap(map_name).colors # Make more general? rgbs = get_cmap(map_name).colors # Make more general?
return [ return [
rgbs[int(n)] rgbs[int(n)]

View file

@ -1,8 +1,6 @@
import os import os
import numpy as np import numpy as np
import validators import validators
import urllib.request
def add_extension_if_not_present(file_name, extension): def add_extension_if_not_present(file_name, extension):
@ -23,6 +21,7 @@ def find_file(file_name, directories=None, extensions=None):
# Check if this is a file online first, and if so, download # Check if this is a file online first, and if so, download
# it to a temporary directory # it to a temporary directory
if validators.url(file_name): if validators.url(file_name):
import urllib.request
from manimlib.utils.directories import get_downloads_dir from manimlib.utils.directories import get_downloads_dir
stem, name = os.path.split(file_name) stem, name = os.path.split(file_name)
folder = get_downloads_dir() folder = get_downloads_dir()

View file

@ -1,37 +1,7 @@
import os
from manimlib.utils.file_ops import find_file from manimlib.utils.file_ops import find_file
from manimlib.utils.directories import get_sound_dir from manimlib.utils.directories import get_sound_dir
def play_chord(*nums):
commands = [
"play",
"-n",
"-c1",
"--no-show-progress",
"synth",
] + [
"sin %-" + str(num)
for num in nums
] + [
"fade h 0.5 1 0.5",
">",
os.devnull
]
try:
os.system(" ".join(commands))
except Exception:
pass
def play_error_sound():
play_chord(11, 8, 6, 1)
def play_finish_sound():
play_chord(12, 9, 5, 2)
def get_full_sound_file_path(sound_file_name): def get_full_sound_file_path(sound_file_name):
return find_file( return find_file(
sound_file_name, sound_file_name,