Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Slightly faster sort_points method, and bug fix in fade

Grant Sanderson7ae5a0eccb13
diff --git a/mobject/mobject.py b/mobject/mobject.py
index ec8a4a03b..53ef69253 100644
--- a/mobject/mobject.py
+++ b/mobject/mobject.py
@@ -194,12 +194,10 @@ class Mobject(object):
function is any map from R^3 to R
"""
for mob in self.get_full_submobject_family():
- indices = range(len(mob.points))
- indices.sort(
- lambda *pair : cmp(*map(function, mob.points[pair, :]))
+ indices = np.argsort(
+ np.apply_along_axis(function, 1, mob.points)
)
- mob.points = mob.points[indices]
- mob.rgbs = mob.rgbs[indices]
+ mob.apply_over_attr_arrays(lambda arr : arr[indices])
return self
def repeat(self, count):
@@ -309,7 +307,7 @@ class Mobject(object):
return self
def fade_to(self, color, alpha):
- self.rgbs = interpolate(self.rgbs, np.array(Color(color).rgb), alpha)
+ self.rgbs = interpolate(self.rgbs, np.array(Color(color).rgb), 1-alpha)
for mob in self.sub_mobjects:
mob.fade_to(color, alpha)
return self