mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Cleaup how colors are updated
This commit is contained in:
parent
b16b107f3e
commit
eee4054da8
1 changed files with 9 additions and 10 deletions
|
@ -5,7 +5,7 @@ from manimlib.constants import *
|
||||||
from manimlib.mobject.mobject import Mobject
|
from manimlib.mobject.mobject import Mobject
|
||||||
from manimlib.utils.bezier import interpolate
|
from manimlib.utils.bezier import interpolate
|
||||||
from manimlib.utils.color import color_to_rgba
|
from manimlib.utils.color import color_to_rgba
|
||||||
from manimlib.utils.color import rgb_to_hex
|
from manimlib.utils.color import rgb_to_color
|
||||||
from manimlib.utils.config_ops import digest_config
|
from manimlib.utils.config_ops import digest_config
|
||||||
from manimlib.utils.images import get_full_raster_image_path
|
from manimlib.utils.images import get_full_raster_image_path
|
||||||
from manimlib.utils.space_ops import normalize_along_axis
|
from manimlib.utils.space_ops import normalize_along_axis
|
||||||
|
@ -88,6 +88,7 @@ class ParametricSurface(Mobject):
|
||||||
return self.triangle_indices
|
return self.triangle_indices
|
||||||
|
|
||||||
def init_colors(self):
|
def init_colors(self):
|
||||||
|
self.rgbas = np.zeros((1, 4))
|
||||||
self.set_color(self.color, self.opacity)
|
self.set_color(self.color, self.opacity)
|
||||||
|
|
||||||
def get_surface_points_and_nudged_points(self):
|
def get_surface_points_and_nudged_points(self):
|
||||||
|
@ -105,20 +106,18 @@ class ParametricSurface(Mobject):
|
||||||
def set_color(self, color, opacity=1.0, family=True):
|
def set_color(self, color, opacity=1.0, family=True):
|
||||||
# TODO, allow for multiple colors
|
# TODO, allow for multiple colors
|
||||||
rgba = color_to_rgba(color, opacity)
|
rgba = color_to_rgba(color, opacity)
|
||||||
self.rgbas = np.array([rgba])
|
mobs = self.get_family() if family else [self]
|
||||||
if family:
|
for mob in mobs:
|
||||||
for submob in self.submobjects:
|
mob.rgbas[:] = rgba
|
||||||
submob.set_color(color, opacity, family)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
return rgb_to_hex(self.rgbas[0, :3])
|
return rgb_to_color(self.rgbas[0, :3])
|
||||||
|
|
||||||
def set_opacity(self, opacity, family=True):
|
def set_opacity(self, opacity, family=True):
|
||||||
self.rgbas[:, 3] = opacity
|
mobs = self.get_family() if family else [self]
|
||||||
if family:
|
for mob in mobs:
|
||||||
for sm in self.submobjects:
|
mob.rgbas[:, 3] = opacity
|
||||||
sm.set_opacity(opacity, family)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def interpolate_color(self, mobject1, mobject2, alpha):
|
def interpolate_color(self, mobject1, mobject2, alpha):
|
||||||
|
|
Loading…
Add table
Reference in a new issue