mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 02:35:22 +08:00
Random cleanup
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,7 +1,7 @@
|
||||
*.pyc
|
||||
animation_files/
|
||||
.DS_Store
|
||||
homeless.py
|
||||
ka_playgrounds/
|
||||
playground.py
|
||||
prettiness_hall_of_fame.py
|
||||
files/
|
@ -153,26 +153,20 @@ class ApplyFunction(Transform):
|
||||
)
|
||||
self.name = "ApplyFunctionTo"+str(mobject)
|
||||
|
||||
class ApplyMatrix(Animation):
|
||||
class ApplyMatrix(ApplyPointwiseFunction):
|
||||
#Truth be told, I'm not sure if this is useful.
|
||||
def __init__(self, matrix, mobject, **kwargs):
|
||||
matrix = np.array(matrix)
|
||||
if matrix.shape == (2, 2):
|
||||
self.matrix = np.identity(3)
|
||||
self.matrix[:2, :2] = matrix
|
||||
elif matrix.shape == (3, 3):
|
||||
self.matrix = matrix
|
||||
else:
|
||||
new_matrix = np.identity(3)
|
||||
new_matrix[:2, :2] = matrix
|
||||
matrix = new_matrix
|
||||
elif matrix.shape != (3, 3):
|
||||
raise "Matrix has bad dimensions"
|
||||
Animation.__init__(self, mobject, **kwargs)
|
||||
|
||||
def update_mobject(self, alpha):
|
||||
matrix = interpolate(np.identity(3), self.matrix, alpha)
|
||||
self.mobject.points = np.dot(
|
||||
self.starting_mobject.points,
|
||||
np.transpose(matrix)
|
||||
)
|
||||
|
||||
transpose = np.transpose(matrix)
|
||||
def func(p):
|
||||
return np.dot(p, transpose)
|
||||
ApplyPointwiseFunction.__init__(self, func, mobject, **kwargs)
|
||||
|
||||
|
||||
class TransformAnimations(Transform):
|
||||
|
@ -129,8 +129,6 @@ class Camera(object):
|
||||
if len(points) == 0:
|
||||
continue
|
||||
coords = self.points_to_pixel_coords(points)
|
||||
if np.all(~self.on_screen_pixels(coords)):
|
||||
return result
|
||||
start = "M%d %d"%tuple(coords[0])
|
||||
#(handle1, handle2, anchor) tripletes
|
||||
triplets = zip(*[
|
||||
|
@ -15,7 +15,7 @@ MEDIUM_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
|
||||
|
||||
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")
|
||||
GIF_DIR = os.path.join(FILE_DIR, "gifs")
|
||||
MOVIE_DIR = os.path.join(FILE_DIR, "movies")
|
||||
|
@ -12,9 +12,22 @@ class SVGMobject(VMobject):
|
||||
}
|
||||
def __init__(self, svg_file, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
self.ensure_valid_file()
|
||||
VMobject.__init__(self, **kwargs)
|
||||
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):
|
||||
doc = minidom.parse(self.svg_file)
|
||||
self.ref_to_element = {}
|
||||
|
@ -34,13 +34,15 @@ class TexMobject(SVGMobject):
|
||||
"next_to_direction" : RIGHT,
|
||||
"next_to_buff" : 0.25,
|
||||
"initial_scale_val" : TEX_MOB_SCALE_VAL,
|
||||
"organize_left_to_right" : True,
|
||||
"propogate_style_to_family" : True,
|
||||
}
|
||||
def __init__(self, expression, **kwargs):
|
||||
digest_config(self, kwargs, locals())
|
||||
VMobject.__init__(self, **kwargs)
|
||||
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):
|
||||
#Overwrite superclass default to use
|
||||
@ -78,7 +80,7 @@ class TexMobject(SVGMobject):
|
||||
self.submobjects = subs
|
||||
return self
|
||||
|
||||
def organize_submobjects(self):
|
||||
def organize_submobjects_left_to_right(self):
|
||||
self.submobjects.sort(
|
||||
lambda m1, m2 : int((m1.get_left()-m2.get_left())[0])
|
||||
)
|
||||
|
@ -106,11 +106,11 @@ class PiCreature(SVGMobject):
|
||||
self.to_corner(DOWN+LEFT)
|
||||
return self
|
||||
|
||||
def get_bubble(self, bubble_type = "thought"):
|
||||
def get_bubble(self, bubble_type = "thought", **kwargs):
|
||||
if bubble_type == "thought":
|
||||
bubble = ThoughtBubble()
|
||||
bubble = ThoughtBubble(**kwargs)
|
||||
elif bubble_type == "speech":
|
||||
bubble = SpeechBubble()
|
||||
bubble = SpeechBubble(**kwargs)
|
||||
else:
|
||||
raise Exception("%s is an invalid bubble type"%bubble_type)
|
||||
bubble.pin_to(self)
|
||||
@ -191,13 +191,19 @@ class Bubble(SVGMobject):
|
||||
self.move_tip_to(mob_center+vector_from_center)
|
||||
return self
|
||||
|
||||
def add_content(self, mobject):
|
||||
if self.content in self.submobjects:
|
||||
self.submobjects.remove(self.content)
|
||||
def position_mobject_inside(self, mobject):
|
||||
scaled_width = self.content_scale_factor*self.get_width()
|
||||
if mobject.get_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.add(self.content)
|
||||
return self
|
||||
|
@ -142,10 +142,13 @@ class Arrow(Line):
|
||||
Line.__init__(self, *args, **kwargs)
|
||||
self.add_tip()
|
||||
|
||||
def add_tip(self):
|
||||
def add_tip(self, add_at_end = True):
|
||||
vect = self.tip_length*RIGHT
|
||||
vect = rotate_vector(vect, self.get_angle()+np.pi)
|
||||
start, end = self.get_start_and_end()
|
||||
if not add_at_end:
|
||||
start, end = end, start
|
||||
vect = -vect
|
||||
tip_points = [
|
||||
end+rotate_vector(vect, u*np.pi/5)
|
||||
for u in 1, -1
|
||||
@ -175,9 +178,8 @@ class Vector(Arrow):
|
||||
class DoubleArrow(Arrow):
|
||||
def __init__(self, *args, **kwargs):
|
||||
Arrow.__init__(self, *args, **kwargs)
|
||||
self.start, self.end = self.end, self.start
|
||||
self.add_tip()
|
||||
self.start, self.end = self.end, self.start
|
||||
self.add_tip(add_at_end = False)
|
||||
|
||||
|
||||
class Cross(VMobject):
|
||||
CONFIG = {
|
||||
|
Reference in New Issue
Block a user