mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 20:43:56 +08:00
Got rid of fade_no_recurse idea
This commit is contained in:
@ -661,34 +661,21 @@ class Mobject(Container):
|
|||||||
self.set_color(self.color)
|
self.set_color(self.color)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Some objects (e.g., VMobjects) have special fading
|
def fade_to(self, color, alpha, family=True):
|
||||||
# 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:
|
if self.get_num_points() > 0:
|
||||||
start = color_to_rgb(self.get_color())
|
new_color = interpolate_color(
|
||||||
end = color_to_rgb(color)
|
self.get_color(), color, alpha
|
||||||
new_rgb = interpolate(start, end, alpha)
|
)
|
||||||
self.set_color(Color(rgb=new_rgb), family=False)
|
self.set_color(new_color, family=False)
|
||||||
|
if family:
|
||||||
|
for submob in self.submobjects:
|
||||||
|
submob.fade_to(color, alpha)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade_to(self, color, alpha):
|
def fade(self, darkness=0.5, family=True):
|
||||||
for mob in self.get_family():
|
if family:
|
||||||
mob.fade_to_no_recurse(color, alpha)
|
for submob in self.submobjects:
|
||||||
return self
|
submob.fade(darkness, family)
|
||||||
|
|
||||||
def fade_no_recurse(self, darkness):
|
|
||||||
self.fade_to_no_recurse(BLACK, darkness)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def fade(self, darkness=0.5):
|
|
||||||
for submob in self.get_family():
|
|
||||||
submob.fade_no_recurse(darkness)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
|
@ -93,8 +93,9 @@ class ImageMobject(AbstractImageMobject):
|
|||||||
self.pixel_array[:, :, 3] = int(255 * alpha)
|
self.pixel_array[:, :, 3] = int(255 * alpha)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade_no_recurse(self, darkness=0.5):
|
def fade(self, darkness=0.5, family=True):
|
||||||
self.set_opacity(1 - darkness)
|
self.set_opacity(1 - darkness)
|
||||||
|
super().fade(darkness, family)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def interpolate_color(self, mobject1, mobject2, alpha):
|
def interpolate_color(self, mobject1, mobject2, alpha):
|
||||||
|
@ -240,11 +240,20 @@ class VMobject(Mobject):
|
|||||||
self.set_stroke(opacity=opacity, family=family)
|
self.set_stroke(opacity=opacity, family=family)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade_no_recurse(self, darkness):
|
def fade(self, darkness=0.5, family=True):
|
||||||
opacity = 1.0 - darkness
|
factor = 1.0 - darkness
|
||||||
self.set_fill(opacity=opacity)
|
self.set_fill(
|
||||||
self.set_stroke(opacity=opacity)
|
opacity=factor * self.get_fill_opacity()
|
||||||
self.set_background_stroke(opacity=opacity)
|
)
|
||||||
|
self.set_stroke(
|
||||||
|
opacity=factor * self.get_stroke_opacity()
|
||||||
|
)
|
||||||
|
self.set_background_stroke(
|
||||||
|
opacity=factor * self.get_stroke_opacity(
|
||||||
|
background=True
|
||||||
|
)
|
||||||
|
)
|
||||||
|
super().fade(darkness, family)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_fill_rgbas(self):
|
def get_fill_rgbas(self):
|
||||||
|
Reference in New Issue
Block a user