mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 21:44:19 +08:00
Changed several files to conform to PEP8
This commit is contained in:
@ -17,6 +17,7 @@ from utils.rate_functions import smooth
|
||||
|
||||
# Drawing
|
||||
|
||||
|
||||
class ShowPartial(Animation):
|
||||
def update_submobject(self, submobject, starting_submobject, alpha):
|
||||
submobject.pointwise_become_partial(
|
||||
@ -26,24 +27,29 @@ class ShowPartial(Animation):
|
||||
def get_bounds(self, alpha):
|
||||
raise Exception("Not Implemented")
|
||||
|
||||
|
||||
class ShowCreation(ShowPartial):
|
||||
CONFIG = {
|
||||
"submobject_mode": "one_at_a_time",
|
||||
}
|
||||
|
||||
def get_bounds(self, alpha):
|
||||
return (0, alpha)
|
||||
|
||||
|
||||
class Uncreate(ShowCreation):
|
||||
CONFIG = {
|
||||
"rate_func": lambda t: smooth(1 - t),
|
||||
"remover": True
|
||||
}
|
||||
|
||||
|
||||
class Write(ShowCreation):
|
||||
CONFIG = {
|
||||
"rate_func": None,
|
||||
"submobject_mode": "lagged_start",
|
||||
}
|
||||
|
||||
def __init__(self, mob_or_text, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
if isinstance(mob_or_text, str):
|
||||
@ -67,6 +73,7 @@ class Write(ShowCreation):
|
||||
else:
|
||||
self.run_time = 2
|
||||
|
||||
|
||||
class DrawBorderThenFill(Animation):
|
||||
CONFIG = {
|
||||
"run_time": 2,
|
||||
@ -74,6 +81,7 @@ class DrawBorderThenFill(Animation):
|
||||
"stroke_color": None,
|
||||
"rate_func": double_smooth,
|
||||
}
|
||||
|
||||
def __init__(self, vmobject, **kwargs):
|
||||
if not isinstance(vmobject, VMobject):
|
||||
raise Exception("DrawBorderThenFill only works for VMobjects")
|
||||
@ -109,10 +117,12 @@ class DrawBorderThenFill(Animation):
|
||||
|
||||
# Fading
|
||||
|
||||
|
||||
class FadeOut(Transform):
|
||||
CONFIG = {
|
||||
"remover": True,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
target.fade(1)
|
||||
@ -122,6 +132,7 @@ class FadeOut(Transform):
|
||||
Transform.clean_up(self, surrounding_scene)
|
||||
self.update(0)
|
||||
|
||||
|
||||
class FadeIn(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
target = mobject.copy()
|
||||
@ -131,10 +142,12 @@ class FadeIn(Transform):
|
||||
self.starting_mobject.set_stroke(width=0)
|
||||
self.starting_mobject.set_fill(opacity=0)
|
||||
|
||||
|
||||
class FadeInAndShiftFromDirection(Transform):
|
||||
CONFIG = {
|
||||
"direction": DOWN,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
@ -142,6 +155,7 @@ class FadeInAndShiftFromDirection(Transform):
|
||||
mobject.fade(1)
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class FadeInFromDown(FadeInAndShiftFromDirection):
|
||||
"""
|
||||
Essential a more convenient form of FadeInAndShiftFromDirection
|
||||
@ -151,10 +165,13 @@ class FadeInFromDown(FadeInAndShiftFromDirection):
|
||||
}
|
||||
|
||||
# Growing
|
||||
|
||||
|
||||
class GrowFromPoint(Transform):
|
||||
CONFIG = {
|
||||
"point_color": None,
|
||||
}
|
||||
|
||||
def __init__(self, mobject, point, **kwargs):
|
||||
digest_config(self, kwargs)
|
||||
target = mobject.copy()
|
||||
@ -165,19 +182,23 @@ class GrowFromPoint(Transform):
|
||||
mobject.set_color(point_mob.get_color())
|
||||
Transform.__init__(self, mobject, target, **kwargs)
|
||||
|
||||
|
||||
class GrowFromCenter(GrowFromPoint):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
GrowFromPoint.__init__(self, mobject, mobject.get_center(), **kwargs)
|
||||
|
||||
|
||||
class GrowArrow(GrowFromPoint):
|
||||
def __init__(self, arrow, **kwargs):
|
||||
GrowFromPoint.__init__(self, arrow, arrow.get_start(), **kwargs)
|
||||
|
||||
|
||||
class SpinInFromNothing(GrowFromCenter):
|
||||
CONFIG = {
|
||||
"path_func": counterclockwise_path()
|
||||
}
|
||||
|
||||
|
||||
class ShrinkToCenter(Transform):
|
||||
def __init__(self, mobject, **kwargs):
|
||||
Transform.__init__(
|
||||
|
@ -25,6 +25,7 @@ from scene.scene import Scene
|
||||
from utils.rate_functions import squish_rate_func
|
||||
from utils.rate_functions import there_and_back
|
||||
|
||||
|
||||
class PiCreatureScene(Scene):
|
||||
CONFIG = {
|
||||
"total_wait_time": 0,
|
||||
@ -36,6 +37,7 @@ class PiCreatureScene(Scene):
|
||||
},
|
||||
"default_pi_creature_start_corner": DOWN + LEFT,
|
||||
}
|
||||
|
||||
def setup(self):
|
||||
self.pi_creatures = self.create_pi_creatures()
|
||||
self.pi_creature = self.get_primary_pi_creature()
|
||||
@ -91,6 +93,7 @@ class PiCreatureScene(Scene):
|
||||
on_screen_mobjects = self.camera.extract_mobject_family_members(
|
||||
self.get_mobjects()
|
||||
)
|
||||
|
||||
def has_bubble(pi):
|
||||
return hasattr(pi, "bubble") and \
|
||||
pi.bubble is not None and \
|
||||
@ -142,10 +145,12 @@ class PiCreatureScene(Scene):
|
||||
)
|
||||
|
||||
def say(self, *content, **kwargs):
|
||||
self.pi_creature_says(self.get_primary_pi_creature(), *content, **kwargs)
|
||||
self.pi_creature_says(
|
||||
self.get_primary_pi_creature(), *content, **kwargs)
|
||||
|
||||
def think(self, *content, **kwargs):
|
||||
self.pi_creature_thinks(self.get_primary_pi_creature(), *content, **kwargs)
|
||||
self.pi_creature_thinks(
|
||||
self.get_primary_pi_creature(), *content, **kwargs)
|
||||
|
||||
def compile_play_args_to_animation_list(self, *args):
|
||||
"""
|
||||
@ -244,6 +249,7 @@ class PiCreatureScene(Scene):
|
||||
for pi in pi_creatures
|
||||
]))
|
||||
|
||||
|
||||
class TeacherStudentsScene(PiCreatureScene):
|
||||
CONFIG = {
|
||||
"student_colors": [BLUE_D, BLUE_E, BLUE_C],
|
||||
@ -251,11 +257,13 @@ class TeacherStudentsScene(PiCreatureScene):
|
||||
"seconds_to_blink": 2,
|
||||
"screen_height": 3,
|
||||
}
|
||||
|
||||
def setup(self):
|
||||
PiCreatureScene.setup(self)
|
||||
self.screen = ScreenRectangle(height=self.screen_height)
|
||||
self.screen.to_corner(UP + LEFT)
|
||||
self.hold_up_spot = self.teacher.get_corner(UP+LEFT) + MED_LARGE_BUFF*UP
|
||||
self.hold_up_spot = self.teacher.get_corner(
|
||||
UP + LEFT) + MED_LARGE_BUFF * UP
|
||||
|
||||
def create_pi_creatures(self):
|
||||
self.teacher = Mortimer()
|
||||
@ -340,6 +348,7 @@ class TeacherStudentsScene(PiCreatureScene):
|
||||
if bubble is None:
|
||||
raise Exception("No pi creatures have a thought bubble")
|
||||
vect = -bubble.get_bubble_center()
|
||||
|
||||
def func(point):
|
||||
centered = point + vect
|
||||
return radius * centered / np.linalg.norm(centered)
|
||||
@ -358,5 +367,3 @@ class TeacherStudentsScene(PiCreatureScene):
|
||||
ReplacementTransform(mobject_copy, mobject),
|
||||
self.teacher.change, target_mode,
|
||||
)
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ from constants import *
|
||||
|
||||
VECTOR_LABEL_SCALE_FACTOR = 0.8
|
||||
|
||||
|
||||
def matrix_to_tex_string(matrix):
|
||||
matrix = np.array(matrix).astype("string")
|
||||
if matrix.ndim == 1:
|
||||
@ -25,9 +26,11 @@ def matrix_to_tex_string(matrix):
|
||||
]
|
||||
return prefix + " \\\\ ".join(rows) + suffix
|
||||
|
||||
|
||||
def matrix_to_mobject(matrix):
|
||||
return TexMobject(matrix_to_tex_string(matrix))
|
||||
|
||||
|
||||
def vector_coordinate_label(vector_mob, integer_labels=True,
|
||||
n_dim=2, color=WHITE):
|
||||
vect = np.array(vector_mob.get_end())
|
||||
@ -49,12 +52,14 @@ def vector_coordinate_label(vector_mob, integer_labels = True,
|
||||
label.add_to_back(label.rect)
|
||||
return label
|
||||
|
||||
|
||||
class Matrix(VMobject):
|
||||
CONFIG = {
|
||||
"v_buff": 0.5,
|
||||
"h_buff": 1,
|
||||
"add_background_rectangles": False
|
||||
}
|
||||
|
||||
def __init__(self, matrix, **kwargs):
|
||||
"""
|
||||
Matrix can either either include numbres, tex_strings,
|
||||
@ -123,15 +128,3 @@ class Matrix(VMobject):
|
||||
|
||||
def get_brackets(self):
|
||||
return self.brackets
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user