Skip to content

Commit

Permalink
Random cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Jul 12, 2016
1 parent c03a0e6 commit a4efcdb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*.pyc
animation_files/
.DS_Store
homeless.py
ka_playgrounds/
playground.py
prettiness_hall_of_fame.py
files/
24 changes: 9 additions & 15 deletions animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,20 @@ def __init__(self, function, mobject, **kwargs):
)
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):
Expand Down
2 changes: 0 additions & 2 deletions camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ def get_pathstring(self, vmobject):
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(*[
Expand Down
4 changes: 2 additions & 2 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}

LOW_QUALITY_CAMERA_CONFIG = {
"pixel_shape" : (480, 720),
"pixel_shape" : (480, 853),
}


Expand Down Expand Up @@ -53,7 +53,7 @@
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")
Expand Down
13 changes: 13 additions & 0 deletions mobject/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
6 changes: 4 additions & 2 deletions mobject/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +80,7 @@ def handle_list_expression(self):
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])
)
Expand Down
20 changes: 13 additions & 7 deletions topics/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def to_corner(self, vect = None):
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)
Expand Down Expand Up @@ -191,13 +191,19 @@ def pin_to(self, mobject):
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
Expand Down
10 changes: 6 additions & 4 deletions topics/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ def __init__(self, *args, **kwargs):
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
Expand Down Expand Up @@ -175,9 +178,8 @@ def __init__(self, direction, **kwargs):
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 = {
Expand Down

0 comments on commit a4efcdb

Please sign in to comment.