Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed fade to behave over Groups of objects exactly as over the subobjects individually

Sridhar Ramesh0975f323db2a
diff --git a/animation/transform.py b/animation/transform.py
index 433650dff..d8a9a617f 100644
--- a/animation/transform.py
+++ b/animation/transform.py
@@ -162,9 +162,6 @@ class FadeOut(Transform):
def __init__(self, mobject, **kwargs):
target = mobject.copy()
target.fade(1)
- if isinstance(mobject, VMobject):
- target.set_stroke(width = 0)
- target.set_fill(opacity = 0)
Transform.__init__(self, mobject, target, **kwargs)
def clean_up(self, surrounding_scene = None):
diff --git a/mobject/mobject.py b/mobject/mobject.py
index 6618d1aa2..e45f3bee7 100644
--- a/mobject/mobject.py
+++ b/mobject/mobject.py
@@ -524,16 +524,34 @@ class Mobject(Container):
self.highlight(self.color)
return self
- def fade_to(self, color, alpha):
- for mob in self.family_members_with_points():
- start = color_to_rgb(mob.get_color())
+ # Some objects (e.g., VMobjects) have special fading
+ # behavior. We let every object handle its individual
+ # fading via fade_no_recurse (notionally a purely internal method),
+ # and then have fade() itself call this recursively on each submobject
+ #
+ # Similarly for fade_to_no_recurse and fade_to, the underlying functions
+ # used by default for fade()ing
+
+ def fade_to_no_recurse(self, color, alpha):
+ if self.get_num_points() > 0:
+ start = color_to_rgb(self.get_color())
end = color_to_rgb(color)
new_rgb = interpolate(start, end, alpha)
- mob.highlight(Color(rgb = new_rgb), family = False)
+ self.highlight(Color(rgb = new_rgb), family = False)
+ return self
+
+ def fade_to(self, color, alpha):
+ for mob in self.subobject_family():
+ mob.fade_to_no_recurse(self, color, alpha)
+ return self
+
+ def fade_no_recurse(self, darkness):
+ self.fade_to_no_recurse(BLACK, darkness)
return self
def fade(self, darkness = 0.5):
- self.fade_to(BLACK, darkness)
+ for submob in self.submobject_family():
+ submob.fade_no_recurse(darkness)
return self
def get_color(self):
diff --git a/mobject/vectorized_mobject.py b/mobject/vectorized_mobject.py
index 0e4cb2375..a59f1c13a 100644
--- a/mobject/vectorized_mobject.py
+++ b/mobject/vectorized_mobject.py
@@ -113,16 +113,15 @@ class VMobject(Mobject):
sm1.match_style(sm2)
return self
- def fade(self, darkness = 0.5):
- for submob in self.submobject_family():
- submob.set_stroke(
- width = (1-darkness)*submob.get_stroke_width(),
- family = False
- )
- submob.set_fill(
- opacity = (1-darkness)*submob.get_fill_opacity(),
- family = False
- )
+ def fade_no_recurse(self, darkness):
+ self.set_stroke(
+ width = (1-darkness)*self.get_stroke_width(),
+ family = False
+ )
+ self.set_fill(
+ opacity = (1-darkness)*self.get_fill_opacity(),
+ family = False
+ )
return self
def get_fill_rgb(self):