diff --git a/manimlib/__init__.py b/manimlib/__init__.py index 4a63f22d..0b7b39dc 100644 --- a/manimlib/__init__.py +++ b/manimlib/__init__.py @@ -16,15 +16,11 @@ from manimlib.animation.update 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.changing import * from manimlib.mobject.frame import * from manimlib.mobject.functions import * from manimlib.mobject.geometry import * -from manimlib.mobject.interactive import * from manimlib.mobject.matrix import * from manimlib.mobject.mobject 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.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.sample_space_scene import * from manimlib.scene.three_d_scene import * -from manimlib.scene.vector_space_scene import * from manimlib.utils.bezier import * from manimlib.utils.color import * diff --git a/manimlib/animation/animation.py b/manimlib/animation/animation.py index 2d16c891..8a6cd8c9 100644 --- a/manimlib/animation/animation.py +++ b/manimlib/animation/animation.py @@ -1,6 +1,7 @@ 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.rate_functions import smooth from manimlib.utils.simple_functions import clip diff --git a/manimlib/constants.py b/manimlib/constants.py index 5141194e..4273519e 100644 --- a/manimlib/constants.py +++ b/manimlib/constants.py @@ -71,63 +71,68 @@ BOLD = "BOLD" DEFAULT_STROKE_WIDTH = 4 # Colors -COLOR_MAP = { - "BLUE_E": "#1C758A", - "BLUE_D": "#29ABCA", - "BLUE_C": "#58C4DD", - "BLUE_B": "#9CDCEB", - "BLUE_A": "#C7E9F1", - "TEAL_E": "#49A88F", - "TEAL_D": "#55C1A7", - "TEAL_C": "#5CD0B3", - "TEAL_B": "#76DDC0", - "TEAL_A": "#ACEAD7", - "GREEN_E": "#699C52", - "GREEN_D": "#77B05D", - "GREEN_C": "#83C167", - "GREEN_B": "#A6CF8C", - "GREEN_A": "#C9E2AE", - "YELLOW_E": "#E8C11C", - "YELLOW_D": "#F4D345", - "YELLOW_C": "#FFFF00", - "YELLOW_B": "#FFEA94", - "YELLOW_A": "#FFF1B6", - "GOLD_E": "#C78D46", - "GOLD_D": "#E1A158", - "GOLD_C": "#F0AC5F", - "GOLD_B": "#F9B775", - "GOLD_A": "#F7C797", - "RED_E": "#CF5044", - "RED_D": "#E65A4C", - "RED_C": "#FC6255", - "RED_B": "#FF8080", - "RED_A": "#F7A1A3", - "MAROON_E": "#94424F", - "MAROON_D": "#A24D61", - "MAROON_C": "#C55F73", - "MAROON_B": "#EC92AB", - "MAROON_A": "#ECABC1", - "PURPLE_E": "#644172", - "PURPLE_D": "#715582", - "PURPLE_C": "#9A72AC", - "PURPLE_B": "#B189C6", - "PURPLE_A": "#CAA3E8", - "GREY_E": "#222222", - "GREY_D": "#444444", - "GREY_C": "#888888", - "GREY_B": "#BBBBBB", - "GREY_A": "#DDDDDD", - "WHITE": "#FFFFFF", - "BLACK": "#000000", - "GREY_BROWN": "#736357", - "DARK_BROWN": "#8B4513", - "LIGHT_BROWN": "#CD853F", - "PINK": "#D147BD", - "LIGHT_PINK": "#DC75CD", - "GREEN_SCREEN": "#00FF00", - "ORANGE": "#FF862F", -} -PALETTE = list(COLOR_MAP.values()) -locals().update(COLOR_MAP) -for name in [s for s in list(COLOR_MAP.keys()) if s.endswith("_C")]: - locals()[name.replace("_C", "")] = locals()[name] +BLUE_E = "#1C758A" +BLUE_D = "#29ABCA" +BLUE_C = "#58C4DD" +BLUE_B = "#9CDCEB" +BLUE_A = "#C7E9F1" +TEAL_E = "#49A88F" +TEAL_D = "#55C1A7" +TEAL_C = "#5CD0B3" +TEAL_B = "#76DDC0" +TEAL_A = "#ACEAD7" +GREEN_E = "#699C52" +GREEN_D = "#77B05D" +GREEN_C = "#83C167" +GREEN_B = "#A6CF8C" +GREEN_A = "#C9E2AE" +YELLOW_E = "#E8C11C" +YELLOW_D = "#F4D345" +YELLOW_C = "#FFFF00" +YELLOW_B = "#FFEA94" +YELLOW_A = "#FFF1B6" +GOLD_E = "#C78D46" +GOLD_D = "#E1A158" +GOLD_C = "#F0AC5F" +GOLD_B = "#F9B775" +GOLD_A = "#F7C797" +RED_E = "#CF5044" +RED_D = "#E65A4C" +RED_C = "#FC6255" +RED_B = "#FF8080" +RED_A = "#F7A1A3" +MAROON_E = "#94424F" +MAROON_D = "#A24D61" +MAROON_C = "#C55F73" +MAROON_B = "#EC92AB" +MAROON_A = "#ECABC1" +PURPLE_E = "#644172" +PURPLE_D = "#715582" +PURPLE_C = "#9A72AC" +PURPLE_B = "#B189C6" +PURPLE_A = "#CAA3E8" +GREY_E = "#222222" +GREY_D = "#444444" +GREY_C = "#888888" +GREY_B = "#BBBBBB" +GREY_A = "#DDDDDD" +WHITE = "#FFFFFF" +BLACK = "#000000" +GREY_BROWN = "#736357" +DARK_BROWN = "#8B4513" +LIGHT_BROWN = "#CD853F" +PINK = "#D147BD" +LIGHT_PINK = "#DC75CD" +GREEN_SCREEN = "#00FF00" +ORANGE = "#FF862F" + +# Abbreviated names for the "median" colors +BLUE = BLUE_C = "#58C4DD" +TEAL = TEAL_C = "#5CD0B3" +GREEN = GREEN_C = "#83C167" +YELLOW = YELLOW_C = "#FFFF00" +GOLD = GOLD_C = "#F0AC5F" +RED = RED_C = "#FC6255" +MAROON = MAROON_C = "#C55F73" +PURPLE = PURPLE_C = "#9A72AC" +GREY = GREY_C = "#888888" diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index 60cd5fad..5cd2283c 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -9,7 +9,6 @@ from tqdm import tqdm as ProgressDisplay import numpy as np import time import moderngl -from IPython.terminal.embed import InteractiveShellEmbed from manimlib.animation.animation import prepare_animation 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.event_handler.event_type import EventType from manimlib.event_handler import EVENT_DISPATCHER -from manimlib.window import Window class Scene(object): @@ -45,6 +43,7 @@ class Scene(object): def __init__(self, **kwargs): digest_config(self, kwargs) if self.preview: + from manimlib.window import Window self.window = Window(scene=self, **self.window_config) self.camera_config["ctx"] = self.window.ctx else: @@ -119,7 +118,8 @@ class Scene(object): self.stop_skipping() self.linger_after_completion = False self.update_frame() - + + from IPython.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed() # Have the frame update after each command shell.events.register('post_run_cell', lambda *a, **kw: self.update_frame()) diff --git a/manimlib/utils/color.py b/manimlib/utils/color.py index efe5e5b7..d9e0013d 100644 --- a/manimlib/utils/color.py +++ b/manimlib/utils/color.py @@ -2,9 +2,7 @@ import random from colour import Color import numpy as np -from matplotlib.cm import get_cmap -from manimlib.constants import PALETTE from manimlib.constants import WHITE from manimlib.utils.bezier import interpolate from manimlib.utils.simple_functions import clip_in_place @@ -102,7 +100,7 @@ def random_bright_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): @@ -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): + from matplotlib.cm import get_cmap + rgbs = get_cmap(map_name).colors # Make more general? return [ rgbs[int(n)] diff --git a/manimlib/utils/file_ops.py b/manimlib/utils/file_ops.py index 75587761..19322825 100644 --- a/manimlib/utils/file_ops.py +++ b/manimlib/utils/file_ops.py @@ -1,8 +1,6 @@ import os import numpy as np - import validators -import urllib.request 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 # it to a temporary directory if validators.url(file_name): + import urllib.request from manimlib.utils.directories import get_downloads_dir stem, name = os.path.split(file_name) folder = get_downloads_dir() diff --git a/manimlib/utils/sounds.py b/manimlib/utils/sounds.py index 2cc8a124..c2e43269 100644 --- a/manimlib/utils/sounds.py +++ b/manimlib/utils/sounds.py @@ -1,37 +1,7 @@ -import os from manimlib.utils.file_ops import find_file 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): return find_file( sound_file_name,