From ebc53e3948927708aa9432cd9997d0f0b5908fbd Mon Sep 17 00:00:00 2001 From: mirefek Date: Mon, 12 Feb 2018 22:33:41 +0100 Subject: [PATCH 1/3] add requirements for BraceLabel --- topics/objects.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/topics/objects.py b/topics/objects.py index a91c2b33..2ef461fe 100644 --- a/topics/objects.py +++ b/topics/objects.py @@ -3,10 +3,10 @@ from helpers import * from mobject import Mobject from mobject.vectorized_mobject import VGroup, VMobject, VectorizedPoint 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.simple_animations import Rotating, LaggedStart +from animation.simple_animations import Rotating, LaggedStart, AnimationGroup from animation.transform import ApplyMethod, FadeIn, GrowFromCenter from topics.geometry import Circle, Line, Rectangle, Square, \ From bc83c8a4f33f0afc5cf6ca77946f05a0772e0670 Mon Sep 17 00:00:00 2001 From: mirefek Date: Mon, 12 Feb 2018 22:35:51 +0100 Subject: [PATCH 2/3] SVG transforms hopefully finally handled properly --- mobject/svg_mobject.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/mobject/svg_mobject.py b/mobject/svg_mobject.py index 0b3b0b6c..8d0fbbc8 100644 --- a/mobject/svg_mobject.py +++ b/mobject/svg_mobject.py @@ -159,31 +159,52 @@ class SVGMobject(VMobject): x = float(element.getAttribute('x')) #Flip y y = -float(element.getAttribute('y')) + mobject.shift(x*RIGHT+y*UP) except: pass - try: - transform = element.getAttribute('transform') + transform = element.getAttribute('transform') + + try: # transform matrix prefix = "matrix(" suffix = ")" if not transform.startswith(prefix) or not transform.endswith(suffix): raise Exception() transform = transform[len(prefix):-len(suffix)] transform = string_to_numbers(transform) transform = np.array(transform).reshape([3,2]) - x += transform[2][0] - y -= transform[2][1] + x = transform[2][0] + y = -transform[2][1] matrix = np.identity(self.dim) matrix[:2,:2] = transform[:2,:] - t_matrix = np.transpose(matrix) + matrix[1] *= -1 + matrix[:,1] *= -1 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: pass - mobject.shift(x*RIGHT+y*UP) - #TODO, transforms + try: # transform scale + 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): new_refs = dict([ From 6b39ba0502786d63d13671325a78351f89dfd3be Mon Sep 17 00:00:00 2001 From: mirefek Date: Mon, 12 Feb 2018 22:41:34 +0100 Subject: [PATCH 3/3] Feature: argument coor_mask for move_to / next_to: setting coor_mask = X_AXIS or Y_AXIS makes the alignment in just one coordinate --- constants.py | 3 +++ mobject/mobject.py | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/constants.py b/constants.py index 2efb773f..cac15811 100644 --- a/constants.py +++ b/constants.py @@ -53,6 +53,9 @@ RIGHT = np.array(( 1., 0., 0.)) LEFT = np.array((-1., 0., 0.)) IN = 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 BOTTOM = SPACE_HEIGHT*DOWN diff --git a/mobject/mobject.py b/mobject/mobject.py index cf01b713..6618d1aa 100644 --- a/mobject/mobject.py +++ b/mobject/mobject.py @@ -296,6 +296,7 @@ class Mobject(Container): aligned_edge = ORIGIN, submobject_to_align = None, index_of_submobject_to_align = None, + coor_mask = np.array([1,1,1]), ): if isinstance(mobject_or_point, Mobject): mob = mobject_or_point @@ -315,7 +316,7 @@ class Mobject(Container): else: aligner = self 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 def align_to(self, mobject_or_point, direction = ORIGIN, alignment_vect = UP): @@ -403,13 +404,14 @@ class Mobject(Container): submob.scale(1./factor) 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): target = point_or_mobject.get_critical_point(aligned_edge) else: target = point_or_mobject 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 def replace(self, mobject, dim_to_match = 0, stretch = False):