A community-maintained Python framework for creating mathematical animations.
Some simple small speedups
Grant Sanderson2417c063987a
diff --git a/animation/animation.py b/animation/animation.pyindex 30c09b9e5..808ccdb87 100644--- a/animation/animation.py+++ b/animation/animation.py@@ -32,6 +32,7 @@ class Animation(object):self.rate_func = (lambda x : x)if self.name is None:self.name = self.__class__.__name__ + str(self.mobject)+ self.all_families_zipped = self.get_all_families_zipped()self.update(0)def update_config(self, **kwargs):@@ -54,7 +55,7 @@ class Animation(object):self.update_mobject(self.rate_func(alpha))def update_mobject(self, alpha):- families = self.get_all_families_zipped()+ families = self.all_families_zippedfor i, mobs in enumerate(families):sub_alpha = self.get_sub_alpha(alpha, i, len(families))self.update_submobject(*list(mobs) + [sub_alpha])diff --git a/camera.py b/camera.pyindex 8d714af78..f79f7b296 100644--- a/camera.py+++ b/camera.py@@ -98,22 +98,7 @@ class Camera(object):for vmobject in vmobjects:self.display_vectorized(vmobject, canvas)canvas.flush()- self.pixel_array[:,:] = np.array(image)---- def display_region(self, region):- (h, w) = self.pixel_shape- scalar = 2*self.space_shape[0] / h- xs = scalar*np.arange(-w/2, w/2)+self.space_center[0]- ys = -scalar*np.arange(-h/2, h/2)+self.space_center[1]- x_array = np.dot(np.ones((h, 1)), xs.reshape((1, w)))- y_array = np.dot(ys.reshape(h, 1), np.ones((1, w)))- covered = region.condition(x_array, y_array)- rgb = np.array(Color(region.color).get_rgb())- rgb = (255*rgb).astype('uint8')- self.pixel_array[covered] = rgb-+ self.pixel_array[:,:] = imagedef display_vectorized(self, vmobject, canvas):if vmobject.is_subpath:@@ -125,7 +110,6 @@ class Camera(object):symbol = aggdraw.Symbol(pathstring)canvas.symbol((0, 0), symbol, pen, fill)-def get_pen_and_fill(self, vmobject):pen = aggdraw.Pen(self.get_stroke_color(vmobject).get_hex_l(),@@ -195,7 +179,6 @@ class Camera(object):new_pa[indices] = rgbsself.pixel_array = new_pa.reshape((ph, pw, 3))-def align_points_to_camera(self, points):## This is where projection should livereturn points - self.space_centerdiff --git a/helpers.py b/helpers.pyindex a70720909..6b358da3d 100644--- a/helpers.py+++ b/helpers.py@@ -181,7 +181,13 @@ def remove_list_redundancies(l):"""Used instead of list(set(l)) to maintain order"""- return sorted(list(set(l)), lambda a, b : l.index(a) - l.index(b))+ result = []+ used = set()+ for x in l:+ if not x in used:+ result.append(x)+ used.add(x)+ return resultdef list_update(l1, l2):"""