mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 14:03:59 +08:00
Simple and small performance improvements
This commit is contained in:
@ -11,9 +11,12 @@ from utils.simple_functions import clip_in_place
|
||||
|
||||
|
||||
def color_to_rgb(color):
|
||||
if not isinstance(color, Color):
|
||||
color = Color(color)
|
||||
return np.array(color.get_rgb())
|
||||
if isinstance(color, str):
|
||||
return hex_to_rgb(color)
|
||||
elif isinstance(color, Color):
|
||||
return np.array(color.get_rgb())
|
||||
else:
|
||||
raise Exception("Invalid color type")
|
||||
|
||||
|
||||
def color_to_rgba(color, alpha=1):
|
||||
@ -35,6 +38,16 @@ def rgb_to_hex(rgb):
|
||||
return "#" + "".join('%02x' % int(255 * x) for x in rgb)
|
||||
|
||||
|
||||
def hex_to_rgb(hex_code):
|
||||
hex_part = hex_code[1:]
|
||||
if len(hex_part) == 3:
|
||||
"".join([2 * c for c in hex_part])
|
||||
return np.array([
|
||||
int(hex_part[i:i + 2], 16) / 255
|
||||
for i in range(0, 6, 2)
|
||||
])
|
||||
|
||||
|
||||
def invert_color(color):
|
||||
return rgb_to_color(1.0 - color_to_rgb(color))
|
||||
|
||||
|
Reference in New Issue
Block a user