mirror of
https://github.com/3b1b/manim.git
synced 2025-07-29 13:03:31 +08:00
Added set_style, get_style, and improved match_stlye
This commit is contained in:
@ -101,8 +101,8 @@ class VMobject(Mobject):
|
|||||||
return rgbas
|
return rgbas
|
||||||
|
|
||||||
def update_rgbas_array(self, array_name, color=None, opacity=None):
|
def update_rgbas_array(self, array_name, color=None, opacity=None):
|
||||||
passed_color = color or BLACK
|
passed_color = color if (color is not None) else BLACK
|
||||||
passed_opacity = opacity or 0
|
passed_opacity = opacity if (opacity is not None) else 0
|
||||||
rgbas = self.generate_rgbas_array(passed_color, passed_opacity)
|
rgbas = self.generate_rgbas_array(passed_color, passed_opacity)
|
||||||
if not hasattr(self, array_name):
|
if not hasattr(self, array_name):
|
||||||
setattr(self, array_name, rgbas)
|
setattr(self, array_name, rgbas)
|
||||||
@ -155,16 +155,56 @@ class VMobject(Mobject):
|
|||||||
self.set_stroke(**kwargs)
|
self.set_stroke(**kwargs)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_color(self, color, family=True):
|
def set_style(self,
|
||||||
self.set_fill(color, family=family)
|
fill_color=None,
|
||||||
self.set_stroke(color, family=family)
|
fill_opacity=None,
|
||||||
return self
|
stroke_color=None,
|
||||||
|
stroke_width=None,
|
||||||
|
background_stroke_color=None,
|
||||||
|
background_stroke_width=None,
|
||||||
|
sheen_factor=None,
|
||||||
|
sheen_direction=None,
|
||||||
|
background_image_file=None,
|
||||||
|
family=True):
|
||||||
|
self.set_fill(
|
||||||
|
color=fill_color,
|
||||||
|
opacity=fill_opacity,
|
||||||
|
family=family
|
||||||
|
)
|
||||||
|
self.set_stroke(
|
||||||
|
color=stroke_color,
|
||||||
|
width=stroke_width,
|
||||||
|
family=family,
|
||||||
|
)
|
||||||
|
self.set_background_stroke(
|
||||||
|
color=background_stroke_color,
|
||||||
|
width=background_stroke_width,
|
||||||
|
family=family,
|
||||||
|
)
|
||||||
|
if sheen_factor:
|
||||||
|
self.set_sheen(
|
||||||
|
factor=sheen_factor,
|
||||||
|
direction=sheen_direction,
|
||||||
|
family=family,
|
||||||
|
)
|
||||||
|
if background_image_file:
|
||||||
|
self.color_using_background_image(background_image_file)
|
||||||
|
|
||||||
|
def get_style(self):
|
||||||
|
return {
|
||||||
|
"fill_color": self.get_fill_colors(),
|
||||||
|
"fill_opacity": self.get_fill_opacities(),
|
||||||
|
"stroke_color": self.get_stroke_colors(),
|
||||||
|
"stroke_width": self.get_stroke_width(),
|
||||||
|
"background_stroke_color": self.get_stroke_colors(background=True),
|
||||||
|
"background_stroke_width": self.get_stroke_width(background=True),
|
||||||
|
"sheen_factor": self.get_sheen(),
|
||||||
|
"sheen_direction": self.get_sheen_direction(),
|
||||||
|
"background_image_file": self.get_background_image_file(),
|
||||||
|
}
|
||||||
|
|
||||||
def match_style(self, vmobject, family=True):
|
def match_style(self, vmobject, family=True):
|
||||||
for a_name in ["fill_rgbas", "stroke_rgbas", "background_stroke_rgbas"]:
|
self.set_style(**vmobject.get_style(), family=False)
|
||||||
setattr(self, a_name, np.array(getattr(vmobject, a_name)))
|
|
||||||
self.stroke_width = vmobject.stroke_width
|
|
||||||
self.background_stroke_width = vmobject.background_stroke_width
|
|
||||||
|
|
||||||
if family:
|
if family:
|
||||||
# Does its best to match up submobject lists, and
|
# Does its best to match up submobject lists, and
|
||||||
@ -178,6 +218,11 @@ class VMobject(Mobject):
|
|||||||
sm1.match_style(sm2)
|
sm1.match_style(sm2)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def set_color(self, color, family=True):
|
||||||
|
self.set_fill(color, family=family)
|
||||||
|
self.set_stroke(color, family=family)
|
||||||
|
return self
|
||||||
|
|
||||||
def fade_no_recurse(self, darkness):
|
def fade_no_recurse(self, darkness):
|
||||||
opacity = 1.0 - darkness
|
opacity = 1.0 - darkness
|
||||||
self.set_fill(opacity=opacity)
|
self.set_fill(opacity=opacity)
|
||||||
|
Reference in New Issue
Block a user