Merge pull request #379 from 3b1b/lkevinzc-fixes

Change imports to manimlib, remove unused imports, formatting
This commit is contained in:
Devin Neal 2018-12-27 12:21:06 -06:00 committed by GitHub
commit c71879a159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 77 additions and 138 deletions

View file

@ -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)

View file

@ -1,5 +1,3 @@
import numpy as np
from manimlib.animation.composition import LaggedStart
from manimlib.animation.transform import ApplyMethod
from manimlib.constants import *

View file

@ -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))

View file

@ -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)

View file

@ -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

View file

@ -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 = [

View file

@ -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

View file

@ -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

View file

@ -1 +0,0 @@

View file

@ -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

View file

@ -1,5 +1,3 @@
from manimlib.continual_animation.continual_animation import ContinualAnimation

View file

@ -1,5 +1,3 @@
from manimlib.animation.numbers import ChangingDecimal
from manimlib.continual_animation.from_animation import NormalAnimationAsContinualAnimation

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -1,15 +1,12 @@
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,
"height" : 2
"width": 3,
"height": 2
}
def __init__(self, **kwargs):
@ -17,7 +14,5 @@ class PiCreatureClass(VGroup):
for i in range(self.width):
for j in range(self.height):
pi = PiCreature().scale(0.3)
pi.move_to(i*DOWN + j* RIGHT)
pi.move_to(i * DOWN + j * RIGHT)
self.add(pi)

View file

@ -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(

View file

@ -100,44 +100,23 @@ class RemovePiCreatureBubble(AnimationGroup):
surrounding_scene.add(self.pi_creature)
class FlashThroughClass(Animation):
CONFIG = {
"highlight_color" : GREEN,
"highlight_color": GREEN,
}
def __init__(self, mobject, mode = "linear", **kwargs):
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)

View file

@ -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

View file

@ -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,

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -7,10 +7,11 @@ 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
DEFAULT_COUNT_RUN_TIME = 5.0
class CountingScene(Scene):
def count(self, items, item_type = "mobject", *args, **kwargs):
def count(self, items, item_type="mobject", *args, **kwargs):
if item_type == "mobject":
self.count_mobjects(items, *args, **kwargs)
elif item_type == "region":
@ -20,18 +21,19 @@ class CountingScene(Scene):
return self
def count_mobjects(
self, mobjects, mode = "highlight",
color = "red",
display_numbers = True,
num_offset = DEFAULT_COUNT_NUM_OFFSET,
run_time = DEFAULT_COUNT_RUN_TIME):
self, mobjects, mode="highlight",
color="red",
display_numbers=True,
num_offset=DEFAULT_COUNT_NUM_OFFSET,
run_time=DEFAULT_COUNT_RUN_TIME,
):
"""
Note, leaves final number mobject as "number" attribute
mode can be "highlight", "show_creation" or "show", otherwise
a warning is given and nothing is animating during the count
"""
if len(mobjects) > 50: #TODO
if len(mobjects) > 50: # TODO
raise Exception("I don't know if you should be counting \
too many mobjects...")
if len(mobjects) == 0:
@ -52,7 +54,7 @@ class CountingScene(Scene):
self.wait(frame_time)
mob.set_color(original_color)
if mode == "show_creation":
self.play(ShowCreation(mob, run_time = frame_time))
self.play(ShowCreation(mob, run_time=frame_time))
if mode == "show":
self.add(mob)
self.wait(frame_time)
@ -63,10 +65,10 @@ class CountingScene(Scene):
self.number = num_mob
return self
def count_regions(self, regions,
mode = "one_at_a_time",
num_offset = DEFAULT_COUNT_NUM_OFFSET,
run_time = DEFAULT_COUNT_RUN_TIME,
def count_regions(self, regions,
mode="one_at_a_time",
num_offset=DEFAULT_COUNT_NUM_OFFSET,
run_time=DEFAULT_COUNT_RUN_TIME,
**unused_kwargsn):
if mode not in ["one_at_a_time", "show_all"]:
raise Warning("Unknown mode")
@ -84,34 +86,34 @@ class CountingScene(Scene):
self.number = num_mob
return self
def combinationMobject(n,k):
return Integer(choose(n,k))
def combinationMobject(n, k):
return Integer(choose(n, k))
class GeneralizedPascalsTriangle(VMobject):
CONFIG = {
"nrows" : 7,
"height" : FRAME_HEIGHT - 1,
"width" : 1.5*FRAME_X_RADIUS,
"portion_to_fill" : 0.7,
"submob_class" : combinationMobject,
}
"nrows": 7,
"height": FRAME_HEIGHT - 1,
"width": 1.5 * FRAME_X_RADIUS,
"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.bottom_left = (self.cell_width * self.nrows / 2.0) * LEFT + \
(self.cell_height * self.nrows / 2.0) * DOWN
self.coords_to_mobs = {}
self.coords = [
(n, k)
for n in range(self.nrows)
for k in range(n+1)
(n, k)
for n in range(self.nrows)
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))
num_mob = self.submob_class(n, k) # TexMobject(str(num))
scale_factor = min(
1,
self.portion_to_fill * self.cell_height / num_mob.get_height(),
@ -122,20 +124,20 @@ class GeneralizedPascalsTriangle(VMobject):
self.coords_to_mobs[n] = {}
self.coords_to_mobs[n][k] = num_mob
self.add(*[
self.coords_to_mobs[n][k]
self.coords_to_mobs[n][k]
for n, k in self.coords
])
return self
def coords_to_center(self, n, k):
x_offset = self.cell_width * (k+self.nrows/2.0 - n/2.0)
x_offset = self.cell_width * (k + self.nrows / 2.0 - n / 2.0)
y_offset = self.cell_height * (self.nrows - n)
return self.bottom_left + x_offset*RIGHT + y_offset*UP
return self.bottom_left + x_offset * RIGHT + y_offset * UP
def generate_n_choose_k_mobs(self):
self.coords_to_n_choose_k = {}
for n, k in self.coords:
nck_mob = TexMobject(r"{%d \choose %d}"%(n, k))
nck_mob = TexMobject(r"{%d \choose %d}" % (n, k))
scale_factor = min(
1,
self.portion_to_fill * self.cell_height / nck_mob.get_height(),
@ -162,8 +164,8 @@ class GeneralizedPascalsTriangle(VMobject):
zero = TexMobject("0")
self.sea_of_zeros = []
for n in range(self.nrows):
for a in range((self.nrows - n)/2 + 1):
for k in (n + a + 1, -a -1):
for a in range((self.nrows - n) / 2 + 1):
for k in (n + a + 1, -a - 1):
self.coords.append((n, k))
mob = zero.copy()
mob.shift(self.coords_to_center(n, k))
@ -175,20 +177,12 @@ class GeneralizedPascalsTriangle(VMobject):
n = self.nrows - 1
lowest_row = VGroup(*[
self.coords_to_mobs[n][k]
for k in range(n+1)
for k in range(n + 1)
])
return lowest_row
class PascalsTriangle(GeneralizedPascalsTriangle):
CONFIG = {
"submob_class" : combinationMobject,
"submob_class": combinationMobject,
}

View file

@ -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])

View file

@ -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 = []

View file

@ -242,7 +242,7 @@ class Spotlight(VMobject):
projected_screen_points = list(map(self.project, screen_points))
viewing_angles = np.array(list(map(self.viewing_angle_of_point,
projected_screen_points)))
projected_screen_points)))
lower_angle = upper_angle = 0
if len(viewing_angles) != 0:
@ -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()),

View file

@ -99,7 +99,7 @@ def plane_partition(*lines, **kwargs):
def plane_partition_from_points(*points, **kwargs):
"""
Returns list of regions cut out by the complete graph
with points from the argument as vertices.
with points from the argument as vertices.
Each point comes in the form (x, y)
"""

View file

@ -1 +0,0 @@

View file

@ -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)

View file

@ -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(
@ -676,7 +677,7 @@ class Scene(Container):
anims = []
anims.append(Write(eq))
for mobject in self.mobjects:
anims.append(ApplyMethod(mobject.shift,2*UP))
anims.append(ApplyMethod(mobject.shift, 2 * UP))
self.play(*anims)