mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Merge pull request #379 from 3b1b/lkevinzc-fixes
Change imports to manimlib, remove unused imports, formatting
This commit is contained in:
commit
c71879a159
53 changed files with 77 additions and 138 deletions
|
@ -1,4 +1,3 @@
|
|||
import itertools as it
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
@ -104,8 +103,7 @@ class Succession(Animation):
|
|||
self.scene_mobjects_at_time = [None for i in range(self.num_anims + 1)]
|
||||
self.scene_mobjects_at_time[0] = Group()
|
||||
for i in range(self.num_anims):
|
||||
self.scene_mobjects_at_time[i +
|
||||
1] = self.scene_mobjects_at_time[i].copy()
|
||||
self.scene_mobjects_at_time[i + 1] = self.scene_mobjects_at_time[i].copy()
|
||||
self.animations[i].clean_up(self.scene_mobjects_at_time[i + 1])
|
||||
|
||||
self.current_alpha = 0
|
||||
|
@ -154,7 +152,7 @@ class Succession(Animation):
|
|||
# self.critical_alphas (which is also 1.0)
|
||||
if not abs(alpha - 1) < 0.001:
|
||||
warnings.warn(
|
||||
"Rounding error not near alpha=1 in Succession.update_mobject," +
|
||||
"Rounding error not near alpha=1 in Succession.update_mobject,"
|
||||
"instead alpha = %f" % alpha
|
||||
)
|
||||
print(self.critical_alphas, alpha)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import numpy as np
|
||||
|
||||
from manimlib.animation.composition import LaggedStart
|
||||
from manimlib.animation.transform import ApplyMethod
|
||||
from manimlib.constants import *
|
||||
|
|
|
@ -118,7 +118,7 @@ class ApplyMethod(Transform):
|
|||
"""
|
||||
if not inspect.ismethod(method):
|
||||
raise Exception(
|
||||
"Whoops, looks like you accidentally invoked " +
|
||||
"Whoops, looks like you accidentally invoked "
|
||||
"the method you want to animate"
|
||||
)
|
||||
assert(isinstance(method.__self__, Mobject))
|
||||
|
|
|
@ -36,8 +36,6 @@ class MaintainPositionRelativeTo(Animation):
|
|||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
self.mobject.shift(
|
||||
self.tracked_mobject.get_critical_point(self.tracked_critical_point) -
|
||||
self.mobject.get_critical_point(self.tracked_critical_point) +
|
||||
self.diff
|
||||
)
|
||||
target = self.tracked_mobject.get_critical_point(self.tracked_critical_point)
|
||||
location = self.mobject.get_critical_point(self.tracked_critical_point)
|
||||
self.mobject.shift(target - location + self.diff)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from functools import reduce
|
||||
import itertools as it
|
||||
import operator as op
|
||||
|
@ -15,7 +14,6 @@ from manimlib.mobject.mobject import Mobject
|
|||
from manimlib.mobject.types.point_cloud_mobject import PMobject
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.utils.color import color_to_int_rgba
|
||||
from manimlib.utils.color import rgb_to_hex
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.images import get_full_raster_image_path
|
||||
from manimlib.utils.iterables import batch_by_property
|
||||
|
|
|
@ -35,6 +35,7 @@ class MappingCamera(Camera):
|
|||
excluded_mobjects=None,
|
||||
)
|
||||
|
||||
|
||||
# Note: This allows layering of multiple cameras onto the same portion of the pixel array,
|
||||
# the later cameras overwriting the former
|
||||
#
|
||||
|
@ -42,7 +43,6 @@ class MappingCamera(Camera):
|
|||
# CameraPlusOverlay class)
|
||||
|
||||
# TODO, the classes below should likely be deleted
|
||||
|
||||
class OldMultiCamera(Camera):
|
||||
def __init__(self, *cameras_with_start_positions, **kwargs):
|
||||
self.shifted_cameras = [
|
||||
|
|
|
@ -5,7 +5,6 @@ from manimlib.constants import ORIGIN
|
|||
from manimlib.constants import WHITE
|
||||
from manimlib.mobject.frame import ScreenRectangle
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.mobject.types.vectorized_mobject import VectorizedPoint
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from manimlib.mobject.three_d_utils import get_3d_vmob_end_corner_unit_normal
|
|||
from manimlib.mobject.three_d_utils import get_3d_vmob_start_corner
|
||||
from manimlib.mobject.three_d_utils import get_3d_vmob_start_corner_unit_normal
|
||||
from manimlib.mobject.types.point_cloud_mobject import Point
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.mobject.value_tracker import ValueTracker
|
||||
from manimlib.utils.color import get_shaded_rgb
|
||||
from manimlib.utils.simple_functions import clip_in_place
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -42,8 +42,7 @@ class ContinualAnimation(object):
|
|||
dt *= float(self.external_time) / self.start_up_time
|
||||
elif self.external_time > self.end_time - self.wind_down_time:
|
||||
dt *= np.clip(
|
||||
float(self.end_time - self.external_time) /
|
||||
self.wind_down_time,
|
||||
float(self.end_time - self.external_time) / self.wind_down_time,
|
||||
0, 1
|
||||
)
|
||||
self.internal_time += dt
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
from manimlib.continual_animation.continual_animation import ContinualAnimation
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
from manimlib.animation.numbers import ChangingDecimal
|
||||
from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
from manimlib.animation.update import MaintainPositionRelativeTo
|
||||
from manimlib.continual_animation.continual_animation import ContinualAnimation
|
||||
from manimlib.mobject.value_tracker import ValueTracker
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import importlib
|
||||
import inspect
|
||||
import itertools as it
|
||||
import os
|
||||
import platform
|
||||
import subprocess as sp
|
||||
import sys
|
||||
import traceback
|
||||
|
@ -13,7 +13,6 @@ import manimlib.constants
|
|||
|
||||
|
||||
def handle_scene(scene, **config):
|
||||
import platform
|
||||
if config["quiet"]:
|
||||
curr_stdout = sys.stdout
|
||||
sys.stdout = open(os.devnull, "w")
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import random
|
||||
import string
|
||||
|
||||
from manimlib.animation.animation import Animation
|
||||
from manimlib.animation.composition import LaggedStart
|
||||
from manimlib.animation.creation import DrawBorderThenFill
|
||||
from manimlib.animation.creation import FadeIn
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
import warnings
|
||||
|
||||
import numpy as np
|
||||
|
||||
from manimlib.constants import *
|
||||
from manimlib.for_3b1b_videos.pi_creature import PiCreature
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
|
||||
|
||||
class PiCreatureClass(VGroup):
|
||||
CONFIG = {
|
||||
"width": 3,
|
||||
|
@ -19,5 +16,3 @@ class PiCreatureClass(VGroup):
|
|||
pi = PiCreature().scale(0.3)
|
||||
pi.move_to(i * DOWN + j * RIGHT)
|
||||
self.add(pi)
|
||||
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ from manimlib.mobject.svg.tex_mobject import TextMobject
|
|||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.rate_functions import squish_rate_func
|
||||
from manimlib.utils.rate_functions import there_and_back
|
||||
from manimlib.utils.space_ops import get_norm
|
||||
|
||||
pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "designs", "PiCreature")
|
||||
|
@ -60,7 +58,7 @@ class PiCreature(SVGMobject):
|
|||
"%s_%s.svg" % (self.file_name_prefix, mode)
|
||||
)
|
||||
SVGMobject.__init__(self, file_name=svg_file, **kwargs)
|
||||
except:
|
||||
except Exception:
|
||||
warnings.warn("No %s design with mode %s" %
|
||||
(self.file_name_prefix, mode))
|
||||
svg_file = os.path.join(
|
||||
|
|
|
@ -100,44 +100,23 @@ class RemovePiCreatureBubble(AnimationGroup):
|
|||
surrounding_scene.add(self.pi_creature)
|
||||
|
||||
|
||||
|
||||
class FlashThroughClass(Animation):
|
||||
CONFIG = {
|
||||
"highlight_color": GREEN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, mode="linear", **kwargs):
|
||||
|
||||
if not isinstance(mobject, PiCreatureClass):
|
||||
raise Exception("FlashThroughClass mobject must be a PiCreatureClass")
|
||||
digest_config(self, kwargs)
|
||||
self.indices = list(range(mobject.height * mobject.width))
|
||||
|
||||
if mode == "random":
|
||||
np.random.shuffle(self.indices)
|
||||
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
index = int(np.floor(alpha * self.mobject.height * self.mobject.width))
|
||||
|
||||
for pi in self.mobject:
|
||||
pi.set_color(BLUE_E)
|
||||
if index < self.mobject.height * self.mobject.width:
|
||||
self.mobject[self.indices[index]].set_color(self.highlight_color)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import itertools as it
|
||||
import random
|
||||
|
||||
import numpy as np
|
||||
|
||||
from manimlib.animation.transform import ApplyMethod
|
||||
from manimlib.animation.transform import ReplacementTransform
|
||||
from manimlib.animation.transform import Transform
|
||||
|
|
|
@ -19,7 +19,6 @@ from manimlib.utils.iterables import remove_list_redundancies
|
|||
from manimlib.utils.paths import straight_path
|
||||
from manimlib.utils.simple_functions import get_num_args
|
||||
from manimlib.utils.space_ops import angle_of_vector
|
||||
from manimlib.utils.space_ops import complex_to_R3
|
||||
from manimlib.utils.space_ops import get_norm
|
||||
from manimlib.utils.space_ops import rotation_matrix
|
||||
|
||||
|
@ -102,7 +101,7 @@ class Mobject(Container):
|
|||
|
||||
def get_image(self, camera=None):
|
||||
if camera is None:
|
||||
from camera.camera import Camera
|
||||
from manimlib.camera.camera import Camera
|
||||
camera = Camera()
|
||||
camera.capture_mobject(self)
|
||||
return camera.get_image()
|
||||
|
@ -530,7 +529,7 @@ class Mobject(Container):
|
|||
def add_background_rectangle(self, color=BLACK, opacity=0.75, **kwargs):
|
||||
# TODO, this does not behave well when the mobject has points,
|
||||
# since it gets displayed on top
|
||||
from mobject.shape_matchers import BackgroundRectangle
|
||||
from manimlib.mobject.shape_matchers import BackgroundRectangle
|
||||
self.background_rectangle = BackgroundRectangle(
|
||||
self, color=color,
|
||||
fill_opacity=opacity,
|
||||
|
|
|
@ -544,7 +544,7 @@ class Car(SVGMobject):
|
|||
self.set_stroke(color=WHITE, width=0)
|
||||
self.set_fill(self.color, opacity=1)
|
||||
|
||||
from for_3b1b_videos.pi_creature import Randolph
|
||||
from manimlib.for_3b1b_videos.pi_creature import Randolph
|
||||
randy = Randolph(mode="happy")
|
||||
randy.set_height(0.6 * self.get_height())
|
||||
randy.stretch(0.8, 0)
|
||||
|
|
|
@ -520,8 +520,8 @@ class VMobject(Mobject):
|
|||
# Each element of index_allocation is like a bucket,
|
||||
# and its value tells you the appropriate index of
|
||||
# the smaller curve.
|
||||
index_allocation = (np.arange(curr + n - 1) *
|
||||
num_curves) // (curr + n - 1)
|
||||
index_allocation = (
|
||||
np.arange(curr + n - 1) * num_curves) // (curr + n - 1)
|
||||
for index in range(num_curves):
|
||||
curr_bezier_points = self.points[3 * index:3 * index + 4]
|
||||
num_inter_curves = sum(index_allocation == index)
|
||||
|
|
|
@ -66,9 +66,7 @@ class RearrangeEquation(Scene):
|
|||
"""
|
||||
num_start_terms = len(start_terms)
|
||||
all_mobs = np.array(
|
||||
TexMobject(start_terms).split() +
|
||||
TexMobject(end_terms).split()
|
||||
)
|
||||
TexMobject(start_terms).split() + TexMobject(end_terms).split())
|
||||
all_terms = np.array(start_terms + end_terms)
|
||||
for term in set(all_terms):
|
||||
matches = all_terms == term
|
||||
|
|
|
@ -9,6 +9,7 @@ from manimlib.utils.simple_functions import choose
|
|||
DEFAULT_COUNT_NUM_OFFSET = (FRAME_X_RADIUS - 1, FRAME_Y_RADIUS - 1, 0)
|
||||
DEFAULT_COUNT_RUN_TIME = 5.0
|
||||
|
||||
|
||||
class CountingScene(Scene):
|
||||
def count(self, items, item_type="mobject", *args, **kwargs):
|
||||
if item_type == "mobject":
|
||||
|
@ -24,7 +25,8 @@ class CountingScene(Scene):
|
|||
color="red",
|
||||
display_numbers=True,
|
||||
num_offset=DEFAULT_COUNT_NUM_OFFSET,
|
||||
run_time = DEFAULT_COUNT_RUN_TIME):
|
||||
run_time=DEFAULT_COUNT_RUN_TIME,
|
||||
):
|
||||
"""
|
||||
Note, leaves final number mobject as "number" attribute
|
||||
|
||||
|
@ -84,6 +86,7 @@ class CountingScene(Scene):
|
|||
self.number = num_mob
|
||||
return self
|
||||
|
||||
|
||||
def combinationMobject(n, k):
|
||||
return Integer(choose(n, k))
|
||||
|
||||
|
@ -96,12 +99,12 @@ class GeneralizedPascalsTriangle(VMobject):
|
|||
"portion_to_fill": 0.7,
|
||||
"submob_class": combinationMobject,
|
||||
}
|
||||
|
||||
def generate_points(self):
|
||||
self.cell_height = float(self.height) / self.nrows
|
||||
self.cell_width = float(self.width) / self.nrows
|
||||
self.bottom_left = (self.cell_width * self.nrows / 2.0) * LEFT + \
|
||||
(self.cell_height * self.nrows / 2.0) * DOWN
|
||||
num_to_num_mob = {}
|
||||
self.coords_to_mobs = {}
|
||||
self.coords = [
|
||||
(n, k)
|
||||
|
@ -109,7 +112,6 @@ class GeneralizedPascalsTriangle(VMobject):
|
|||
for k in range(n + 1)
|
||||
]
|
||||
for n, k in self.coords:
|
||||
num = choose(n, k)
|
||||
center = self.coords_to_center(n, k)
|
||||
num_mob = self.submob_class(n, k) # TexMobject(str(num))
|
||||
scale_factor = min(
|
||||
|
@ -184,11 +186,3 @@ class PascalsTriangle(GeneralizedPascalsTriangle):
|
|||
CONFIG = {
|
||||
"submob_class": combinationMobject,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -296,8 +296,8 @@ class JaggedCurvePiece(VMobject):
|
|||
if self.get_num_anchor_points() == 0:
|
||||
self.points = np.zeros((1, 3))
|
||||
anchors = self.get_anchors()
|
||||
indices = np.linspace(0, len(anchors) - 1, n +
|
||||
len(anchors)).astype('int')
|
||||
indices = np.linspace(0, len(anchors) - 1, n + len(anchors)) \
|
||||
.astype('int')
|
||||
self.set_points_as_corners(anchors[indices])
|
||||
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@ from manimlib.utils.space_ops import center_of_mass
|
|||
class Graph():
|
||||
def __init__(self):
|
||||
# List of points in R^3
|
||||
vertices = []
|
||||
# vertices = []
|
||||
# List of pairs of indices of vertices
|
||||
edges = []
|
||||
# edges = []
|
||||
# List of tuples of indices of vertices. The last should
|
||||
# be a cycle whose interior is the entire graph, and when
|
||||
# regions are computed its complement will be taken.
|
||||
region_cycles = []
|
||||
# region_cycles = []
|
||||
|
||||
self.construct()
|
||||
|
||||
|
@ -275,7 +275,7 @@ class DiscreteGraphScene(Scene):
|
|||
])
|
||||
|
||||
def trace_cycle(self, cycle=None, color="yellow", run_time=2.0):
|
||||
if cycle == None:
|
||||
if cycle is None:
|
||||
cycle = self.graph.region_cycles[0]
|
||||
time_per_edge = run_time / len(cycle)
|
||||
next_in_cycle = it.cycle(cycle)
|
||||
|
@ -385,8 +385,7 @@ class DiscreteGraphScene(Scene):
|
|||
Dot(point).set_color("green")
|
||||
for point in self.dual_points
|
||||
]
|
||||
self.dual_vertices[-1] = Circle().scale(FRAME_X_RADIUS +
|
||||
FRAME_Y_RADIUS)
|
||||
self.dual_vertices[-1] = Circle().scale(FRAME_X_RADIUS + FRAME_Y_RADIUS)
|
||||
self.dual_points[-1] = point_at_infinity
|
||||
|
||||
self.dual_edges = []
|
||||
|
|
|
@ -420,7 +420,7 @@ class LightSource(VMobject):
|
|||
else:
|
||||
# Note: See below
|
||||
index = self.submobjects.index(self.spotlight)
|
||||
camera_mob = self.spotlight.camera_mob
|
||||
# camera_mob = self.spotlight.camera_mob
|
||||
self.remove(self.spotlight)
|
||||
self.spotlight = Spotlight(
|
||||
source_point=VectorizedPoint(location=self.get_source_point()),
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -440,7 +440,7 @@ class GraphScene(Scene):
|
|||
triangle.move_to(self.coords_to_point(x_val, 0), UP)
|
||||
triangle.set_fill(color, 1)
|
||||
triangle.set_stroke(width=0)
|
||||
if label == None:
|
||||
if label is None:
|
||||
T_label = TexMobject(self.variable_point_label, fill_color=color)
|
||||
else:
|
||||
T_label = TexMobject(label, fill_color=color)
|
||||
|
|
|
@ -2,7 +2,6 @@ from time import sleep
|
|||
import _thread as thread
|
||||
import datetime
|
||||
import inspect
|
||||
import itertools as it
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
|
@ -26,6 +25,7 @@ from manimlib.utils.output_directory_getters import add_extension_if_not_present
|
|||
from manimlib.utils.output_directory_getters import get_image_output_directory
|
||||
from manimlib.utils.output_directory_getters import get_movie_output_directory
|
||||
|
||||
|
||||
class Scene(Container):
|
||||
CONFIG = {
|
||||
"camera_class": Camera,
|
||||
|
@ -274,8 +274,9 @@ class Scene(Container):
|
|||
for list_name in "mobjects", "foreground_mobjects":
|
||||
self.restructure_mobjects(mobjects, list_name, False)
|
||||
|
||||
self.continual_animations = [ca for ca in self.continual_animations if ca not in continual_animations and
|
||||
ca.mobject not in to_remove]
|
||||
self.continual_animations = [
|
||||
ca for ca in self.continual_animations if ca not in
|
||||
continual_animations and ca.mobject not in to_remove]
|
||||
return self
|
||||
|
||||
def restructure_mobjects(
|
||||
|
|
Loading…
Add table
Reference in a new issue