mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Merge pull request #120 from mirefek/master
yet another simple fixes / improvements
This commit is contained in:
commit
e98252dfa6
4 changed files with 40 additions and 14 deletions
|
@ -53,6 +53,9 @@ RIGHT = np.array(( 1., 0., 0.))
|
||||||
LEFT = np.array((-1., 0., 0.))
|
LEFT = np.array((-1., 0., 0.))
|
||||||
IN = np.array(( 0., 0.,-1.))
|
IN = np.array(( 0., 0.,-1.))
|
||||||
OUT = np.array(( 0., 0., 1.))
|
OUT = np.array(( 0., 0., 1.))
|
||||||
|
X_AXIS = np.array(( 1., 0., 0.))
|
||||||
|
Y_AXIS = np.array(( 0., 1., 0.))
|
||||||
|
Z_AXIS = np.array(( 0., 0., 1.))
|
||||||
|
|
||||||
TOP = SPACE_HEIGHT*UP
|
TOP = SPACE_HEIGHT*UP
|
||||||
BOTTOM = SPACE_HEIGHT*DOWN
|
BOTTOM = SPACE_HEIGHT*DOWN
|
||||||
|
|
|
@ -296,6 +296,7 @@ class Mobject(Container):
|
||||||
aligned_edge = ORIGIN,
|
aligned_edge = ORIGIN,
|
||||||
submobject_to_align = None,
|
submobject_to_align = None,
|
||||||
index_of_submobject_to_align = None,
|
index_of_submobject_to_align = None,
|
||||||
|
coor_mask = np.array([1,1,1]),
|
||||||
):
|
):
|
||||||
if isinstance(mobject_or_point, Mobject):
|
if isinstance(mobject_or_point, Mobject):
|
||||||
mob = mobject_or_point
|
mob = mobject_or_point
|
||||||
|
@ -315,7 +316,7 @@ class Mobject(Container):
|
||||||
else:
|
else:
|
||||||
aligner = self
|
aligner = self
|
||||||
point_to_align = aligner.get_critical_point(aligned_edge - direction)
|
point_to_align = aligner.get_critical_point(aligned_edge - direction)
|
||||||
self.shift(target_point - point_to_align + buff*direction)
|
self.shift((target_point - point_to_align + buff*direction)*coor_mask)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def align_to(self, mobject_or_point, direction = ORIGIN, alignment_vect = UP):
|
def align_to(self, mobject_or_point, direction = ORIGIN, alignment_vect = UP):
|
||||||
|
@ -403,13 +404,14 @@ class Mobject(Container):
|
||||||
submob.scale(1./factor)
|
submob.scale(1./factor)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def move_to(self, point_or_mobject, aligned_edge = ORIGIN):
|
def move_to(self, point_or_mobject, aligned_edge = ORIGIN,
|
||||||
|
coor_mask = np.array([1,1,1])):
|
||||||
if isinstance(point_or_mobject, Mobject):
|
if isinstance(point_or_mobject, Mobject):
|
||||||
target = point_or_mobject.get_critical_point(aligned_edge)
|
target = point_or_mobject.get_critical_point(aligned_edge)
|
||||||
else:
|
else:
|
||||||
target = point_or_mobject
|
target = point_or_mobject
|
||||||
point_to_align = self.get_critical_point(aligned_edge)
|
point_to_align = self.get_critical_point(aligned_edge)
|
||||||
self.shift(target - point_to_align)
|
self.shift((target - point_to_align)*coor_mask)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def replace(self, mobject, dim_to_match = 0, stretch = False):
|
def replace(self, mobject, dim_to_match = 0, stretch = False):
|
||||||
|
|
|
@ -159,31 +159,52 @@ class SVGMobject(VMobject):
|
||||||
x = float(element.getAttribute('x'))
|
x = float(element.getAttribute('x'))
|
||||||
#Flip y
|
#Flip y
|
||||||
y = -float(element.getAttribute('y'))
|
y = -float(element.getAttribute('y'))
|
||||||
|
mobject.shift(x*RIGHT+y*UP)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
|
||||||
transform = element.getAttribute('transform')
|
transform = element.getAttribute('transform')
|
||||||
|
|
||||||
|
try: # transform matrix
|
||||||
prefix = "matrix("
|
prefix = "matrix("
|
||||||
suffix = ")"
|
suffix = ")"
|
||||||
if not transform.startswith(prefix) or not transform.endswith(suffix): raise Exception()
|
if not transform.startswith(prefix) or not transform.endswith(suffix): raise Exception()
|
||||||
transform = transform[len(prefix):-len(suffix)]
|
transform = transform[len(prefix):-len(suffix)]
|
||||||
transform = string_to_numbers(transform)
|
transform = string_to_numbers(transform)
|
||||||
transform = np.array(transform).reshape([3,2])
|
transform = np.array(transform).reshape([3,2])
|
||||||
x += transform[2][0]
|
x = transform[2][0]
|
||||||
y -= transform[2][1]
|
y = -transform[2][1]
|
||||||
matrix = np.identity(self.dim)
|
matrix = np.identity(self.dim)
|
||||||
matrix[:2,:2] = transform[:2,:]
|
matrix[:2,:2] = transform[:2,:]
|
||||||
t_matrix = np.transpose(matrix)
|
matrix[1] *= -1
|
||||||
|
matrix[:,1] *= -1
|
||||||
|
|
||||||
for mob in mobject.family_members_with_points():
|
for mob in mobject.family_members_with_points():
|
||||||
mob.points = np.dot(mob.points, t_matrix)
|
mob.points = np.dot(mob.points, matrix)
|
||||||
|
mobject.shift(x*RIGHT+y*UP)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
mobject.shift(x*RIGHT+y*UP)
|
try: # transform scale
|
||||||
#TODO, transforms
|
prefix = "scale("
|
||||||
|
suffix = ")"
|
||||||
|
if not transform.startswith(prefix) or not transform.endswith(suffix): raise Exception()
|
||||||
|
transform = transform[len(prefix):-len(suffix)]
|
||||||
|
scale_x, scale_y = string_to_numbers(transform)
|
||||||
|
mobject.scale(np.array([scale_x, scale_y, 1]))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try: # transform translate
|
||||||
|
prefix = "translate("
|
||||||
|
suffix = ")"
|
||||||
|
if not transform.startswith(prefix) or not transform.endswith(suffix): raise Exception()
|
||||||
|
transform = transform[len(prefix):-len(suffix)]
|
||||||
|
x, y = string_to_numbers(transform)
|
||||||
|
mobject.shift(x*RIGHT + y*DOWN)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
#TODO, ...
|
||||||
|
|
||||||
def update_ref_to_element(self, defs):
|
def update_ref_to_element(self, defs):
|
||||||
new_refs = dict([
|
new_refs = dict([
|
||||||
|
|
|
@ -3,10 +3,10 @@ from helpers import *
|
||||||
from mobject import Mobject
|
from mobject import Mobject
|
||||||
from mobject.vectorized_mobject import VGroup, VMobject, VectorizedPoint
|
from mobject.vectorized_mobject import VGroup, VMobject, VectorizedPoint
|
||||||
from mobject.svg_mobject import SVGMobject
|
from mobject.svg_mobject import SVGMobject
|
||||||
from mobject.tex_mobject import TextMobject, TexMobject
|
from mobject.tex_mobject import TextMobject, TexMobject, Brace
|
||||||
|
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
from animation.simple_animations import Rotating, LaggedStart
|
from animation.simple_animations import Rotating, LaggedStart, AnimationGroup
|
||||||
from animation.transform import ApplyMethod, FadeIn, GrowFromCenter
|
from animation.transform import ApplyMethod, FadeIn, GrowFromCenter
|
||||||
|
|
||||||
from topics.geometry import Circle, Line, Rectangle, Square, \
|
from topics.geometry import Circle, Line, Rectangle, Square, \
|
||||||
|
|
Loading…
Add table
Reference in a new issue