mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 14:03:59 +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):
|
||||
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):
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
Reference in New Issue
Block a user