mirror of
https://github.com/3b1b/manim.git
synced 2025-08-01 08:54:38 +08:00
Fixed fade to behave over Groups of objects exactly as over the subobjects individually
This commit is contained in:
@ -162,9 +162,6 @@ class FadeOut(Transform):
|
|||||||
def __init__(self, mobject, **kwargs):
|
def __init__(self, mobject, **kwargs):
|
||||||
target = mobject.copy()
|
target = mobject.copy()
|
||||||
target.fade(1)
|
target.fade(1)
|
||||||
if isinstance(mobject, VMobject):
|
|
||||||
target.set_stroke(width = 0)
|
|
||||||
target.set_fill(opacity = 0)
|
|
||||||
Transform.__init__(self, mobject, target, **kwargs)
|
Transform.__init__(self, mobject, target, **kwargs)
|
||||||
|
|
||||||
def clean_up(self, surrounding_scene = None):
|
def clean_up(self, surrounding_scene = None):
|
||||||
|
@ -524,16 +524,34 @@ class Mobject(Container):
|
|||||||
self.highlight(self.color)
|
self.highlight(self.color)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade_to(self, color, alpha):
|
# Some objects (e.g., VMobjects) have special fading
|
||||||
for mob in self.family_members_with_points():
|
# behavior. We let every object handle its individual
|
||||||
start = color_to_rgb(mob.get_color())
|
# 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)
|
end = color_to_rgb(color)
|
||||||
new_rgb = interpolate(start, end, alpha)
|
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
|
return self
|
||||||
|
|
||||||
def fade(self, darkness = 0.5):
|
def fade(self, darkness = 0.5):
|
||||||
self.fade_to(BLACK, darkness)
|
for submob in self.submobject_family():
|
||||||
|
submob.fade_no_recurse(darkness)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
|
@ -113,16 +113,15 @@ class VMobject(Mobject):
|
|||||||
sm1.match_style(sm2)
|
sm1.match_style(sm2)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade(self, darkness = 0.5):
|
def fade_no_recurse(self, darkness):
|
||||||
for submob in self.submobject_family():
|
self.set_stroke(
|
||||||
submob.set_stroke(
|
width = (1-darkness)*self.get_stroke_width(),
|
||||||
width = (1-darkness)*submob.get_stroke_width(),
|
family = False
|
||||||
family = False
|
)
|
||||||
)
|
self.set_fill(
|
||||||
submob.set_fill(
|
opacity = (1-darkness)*self.get_fill_opacity(),
|
||||||
opacity = (1-darkness)*submob.get_fill_opacity(),
|
family = False
|
||||||
family = False
|
)
|
||||||
)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_fill_rgb(self):
|
def get_fill_rgb(self):
|
||||||
|
Reference in New Issue
Block a user