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