mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Random cleanup
This commit is contained in:
parent
c03a0e6bbd
commit
a4efcdbff2
8 changed files with 48 additions and 33 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,7 +1,7 @@
|
||||||
*.pyc
|
*.pyc
|
||||||
animation_files/
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
homeless.py
|
homeless.py
|
||||||
ka_playgrounds/
|
ka_playgrounds/
|
||||||
playground.py
|
playground.py
|
||||||
prettiness_hall_of_fame.py
|
prettiness_hall_of_fame.py
|
||||||
|
files/
|
|
@ -153,26 +153,20 @@ class ApplyFunction(Transform):
|
||||||
)
|
)
|
||||||
self.name = "ApplyFunctionTo"+str(mobject)
|
self.name = "ApplyFunctionTo"+str(mobject)
|
||||||
|
|
||||||
class ApplyMatrix(Animation):
|
class ApplyMatrix(ApplyPointwiseFunction):
|
||||||
#Truth be told, I'm not sure if this is useful.
|
#Truth be told, I'm not sure if this is useful.
|
||||||
def __init__(self, matrix, mobject, **kwargs):
|
def __init__(self, matrix, mobject, **kwargs):
|
||||||
matrix = np.array(matrix)
|
matrix = np.array(matrix)
|
||||||
if matrix.shape == (2, 2):
|
if matrix.shape == (2, 2):
|
||||||
self.matrix = np.identity(3)
|
new_matrix = np.identity(3)
|
||||||
self.matrix[:2, :2] = matrix
|
new_matrix[:2, :2] = matrix
|
||||||
elif matrix.shape == (3, 3):
|
matrix = new_matrix
|
||||||
self.matrix = matrix
|
elif matrix.shape != (3, 3):
|
||||||
else:
|
|
||||||
raise "Matrix has bad dimensions"
|
raise "Matrix has bad dimensions"
|
||||||
Animation.__init__(self, mobject, **kwargs)
|
transpose = np.transpose(matrix)
|
||||||
|
def func(p):
|
||||||
def update_mobject(self, alpha):
|
return np.dot(p, transpose)
|
||||||
matrix = interpolate(np.identity(3), self.matrix, alpha)
|
ApplyPointwiseFunction.__init__(self, func, mobject, **kwargs)
|
||||||
self.mobject.points = np.dot(
|
|
||||||
self.starting_mobject.points,
|
|
||||||
np.transpose(matrix)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TransformAnimations(Transform):
|
class TransformAnimations(Transform):
|
||||||
|
|
|
@ -129,8 +129,6 @@ class Camera(object):
|
||||||
if len(points) == 0:
|
if len(points) == 0:
|
||||||
continue
|
continue
|
||||||
coords = self.points_to_pixel_coords(points)
|
coords = self.points_to_pixel_coords(points)
|
||||||
if np.all(~self.on_screen_pixels(coords)):
|
|
||||||
return result
|
|
||||||
start = "M%d %d"%tuple(coords[0])
|
start = "M%d %d"%tuple(coords[0])
|
||||||
#(handle1, handle2, anchor) tripletes
|
#(handle1, handle2, anchor) tripletes
|
||||||
triplets = zip(*[
|
triplets = zip(*[
|
||||||
|
|
|
@ -15,7 +15,7 @@ MEDIUM_QUALITY_CAMERA_CONFIG = {
|
||||||
}
|
}
|
||||||
|
|
||||||
LOW_QUALITY_CAMERA_CONFIG = {
|
LOW_QUALITY_CAMERA_CONFIG = {
|
||||||
"pixel_shape" : (480, 720),
|
"pixel_shape" : (480, 853),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ LEFT_SIDE = SPACE_WIDTH*LEFT
|
||||||
RIGHT_SIDE = SPACE_WIDTH*RIGHT
|
RIGHT_SIDE = SPACE_WIDTH*RIGHT
|
||||||
|
|
||||||
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
|
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
|
||||||
FILE_DIR = os.path.join(THIS_DIR, "animation_files")
|
FILE_DIR = os.path.join(THIS_DIR, "files")
|
||||||
IMAGE_DIR = os.path.join(FILE_DIR, "images")
|
IMAGE_DIR = os.path.join(FILE_DIR, "images")
|
||||||
GIF_DIR = os.path.join(FILE_DIR, "gifs")
|
GIF_DIR = os.path.join(FILE_DIR, "gifs")
|
||||||
MOVIE_DIR = os.path.join(FILE_DIR, "movies")
|
MOVIE_DIR = os.path.join(FILE_DIR, "movies")
|
||||||
|
|
|
@ -12,9 +12,22 @@ class SVGMobject(VMobject):
|
||||||
}
|
}
|
||||||
def __init__(self, svg_file, **kwargs):
|
def __init__(self, svg_file, **kwargs):
|
||||||
digest_config(self, kwargs, locals())
|
digest_config(self, kwargs, locals())
|
||||||
|
self.ensure_valid_file()
|
||||||
VMobject.__init__(self, **kwargs)
|
VMobject.__init__(self, **kwargs)
|
||||||
self.move_into_position()
|
self.move_into_position()
|
||||||
|
|
||||||
|
def ensure_valid_file(self):
|
||||||
|
possible_paths = [
|
||||||
|
self.svg_file,
|
||||||
|
os.path.join(IMAGE_DIR, self.svg_file),
|
||||||
|
os.path.join(IMAGE_DIR, self.svg_file + ".svg"),
|
||||||
|
]
|
||||||
|
for path in possible_paths:
|
||||||
|
if os.path.exists(path):
|
||||||
|
self.svg_file = path
|
||||||
|
return
|
||||||
|
raise IOError("No file matching %s in image directory"%self.svg_file)
|
||||||
|
|
||||||
def generate_points(self):
|
def generate_points(self):
|
||||||
doc = minidom.parse(self.svg_file)
|
doc = minidom.parse(self.svg_file)
|
||||||
self.ref_to_element = {}
|
self.ref_to_element = {}
|
||||||
|
|
|
@ -34,13 +34,15 @@ class TexMobject(SVGMobject):
|
||||||
"next_to_direction" : RIGHT,
|
"next_to_direction" : RIGHT,
|
||||||
"next_to_buff" : 0.25,
|
"next_to_buff" : 0.25,
|
||||||
"initial_scale_val" : TEX_MOB_SCALE_VAL,
|
"initial_scale_val" : TEX_MOB_SCALE_VAL,
|
||||||
|
"organize_left_to_right" : True,
|
||||||
"propogate_style_to_family" : True,
|
"propogate_style_to_family" : True,
|
||||||
}
|
}
|
||||||
def __init__(self, expression, **kwargs):
|
def __init__(self, expression, **kwargs):
|
||||||
digest_config(self, kwargs, locals())
|
digest_config(self, kwargs, locals())
|
||||||
VMobject.__init__(self, **kwargs)
|
VMobject.__init__(self, **kwargs)
|
||||||
self.move_into_position()
|
self.move_into_position()
|
||||||
self.organize_submobjects()
|
if self.organize_left_to_right:
|
||||||
|
self.organize_submobjects_left_to_right()
|
||||||
|
|
||||||
def path_string_to_mobject(self, path_string):
|
def path_string_to_mobject(self, path_string):
|
||||||
#Overwrite superclass default to use
|
#Overwrite superclass default to use
|
||||||
|
@ -78,7 +80,7 @@ class TexMobject(SVGMobject):
|
||||||
self.submobjects = subs
|
self.submobjects = subs
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def organize_submobjects(self):
|
def organize_submobjects_left_to_right(self):
|
||||||
self.submobjects.sort(
|
self.submobjects.sort(
|
||||||
lambda m1, m2 : int((m1.get_left()-m2.get_left())[0])
|
lambda m1, m2 : int((m1.get_left()-m2.get_left())[0])
|
||||||
)
|
)
|
||||||
|
|
|
@ -106,11 +106,11 @@ class PiCreature(SVGMobject):
|
||||||
self.to_corner(DOWN+LEFT)
|
self.to_corner(DOWN+LEFT)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_bubble(self, bubble_type = "thought"):
|
def get_bubble(self, bubble_type = "thought", **kwargs):
|
||||||
if bubble_type == "thought":
|
if bubble_type == "thought":
|
||||||
bubble = ThoughtBubble()
|
bubble = ThoughtBubble(**kwargs)
|
||||||
elif bubble_type == "speech":
|
elif bubble_type == "speech":
|
||||||
bubble = SpeechBubble()
|
bubble = SpeechBubble(**kwargs)
|
||||||
else:
|
else:
|
||||||
raise Exception("%s is an invalid bubble type"%bubble_type)
|
raise Exception("%s is an invalid bubble type"%bubble_type)
|
||||||
bubble.pin_to(self)
|
bubble.pin_to(self)
|
||||||
|
@ -191,13 +191,19 @@ class Bubble(SVGMobject):
|
||||||
self.move_tip_to(mob_center+vector_from_center)
|
self.move_tip_to(mob_center+vector_from_center)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def add_content(self, mobject):
|
def position_mobject_inside(self, mobject):
|
||||||
if self.content in self.submobjects:
|
|
||||||
self.submobjects.remove(self.content)
|
|
||||||
scaled_width = self.content_scale_factor*self.get_width()
|
scaled_width = self.content_scale_factor*self.get_width()
|
||||||
if mobject.get_width() > scaled_width:
|
if mobject.get_width() > scaled_width:
|
||||||
mobject.scale_to_fit_width(scaled_width)
|
mobject.scale_to_fit_width(scaled_width)
|
||||||
mobject.shift(self.get_bubble_center())
|
mobject.shift(
|
||||||
|
self.get_bubble_center() - mobject.get_center()
|
||||||
|
)
|
||||||
|
return mobject
|
||||||
|
|
||||||
|
def add_content(self, mobject):
|
||||||
|
if self.content in self.submobjects:
|
||||||
|
self.submobjects.remove(self.content)
|
||||||
|
self.position_mobject_inside(mobject)
|
||||||
self.content = mobject
|
self.content = mobject
|
||||||
self.add(self.content)
|
self.add(self.content)
|
||||||
return self
|
return self
|
||||||
|
|
|
@ -142,10 +142,13 @@ class Arrow(Line):
|
||||||
Line.__init__(self, *args, **kwargs)
|
Line.__init__(self, *args, **kwargs)
|
||||||
self.add_tip()
|
self.add_tip()
|
||||||
|
|
||||||
def add_tip(self):
|
def add_tip(self, add_at_end = True):
|
||||||
vect = self.tip_length*RIGHT
|
vect = self.tip_length*RIGHT
|
||||||
vect = rotate_vector(vect, self.get_angle()+np.pi)
|
vect = rotate_vector(vect, self.get_angle()+np.pi)
|
||||||
start, end = self.get_start_and_end()
|
start, end = self.get_start_and_end()
|
||||||
|
if not add_at_end:
|
||||||
|
start, end = end, start
|
||||||
|
vect = -vect
|
||||||
tip_points = [
|
tip_points = [
|
||||||
end+rotate_vector(vect, u*np.pi/5)
|
end+rotate_vector(vect, u*np.pi/5)
|
||||||
for u in 1, -1
|
for u in 1, -1
|
||||||
|
@ -175,9 +178,8 @@ class Vector(Arrow):
|
||||||
class DoubleArrow(Arrow):
|
class DoubleArrow(Arrow):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Arrow.__init__(self, *args, **kwargs)
|
Arrow.__init__(self, *args, **kwargs)
|
||||||
self.start, self.end = self.end, self.start
|
self.add_tip(add_at_end = False)
|
||||||
self.add_tip()
|
|
||||||
self.start, self.end = self.end, self.start
|
|
||||||
|
|
||||||
class Cross(VMobject):
|
class Cross(VMobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue