Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions manim/utils/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
]

import random
import warnings
from typing import Iterable

import numpy as np
Expand Down Expand Up @@ -281,7 +282,14 @@
]



def color_to_rgb(color: Color | str) -> np.ndarray:
warnings.warn(
"This method is not guaranteed to stay around. "
"Please refer to colour module `Color.get_rgb` for Color to rgb conversion",
DeprecationWarning,
stacklevel=2,
)
if isinstance(color, str):
return hex_to_rgb(color)
elif isinstance(color, Color):
Expand All @@ -303,10 +311,22 @@ def rgba_to_color(rgba: Iterable[float]) -> Color:


def rgb_to_hex(rgb: Iterable[float]) -> str:
warnings.warn(
"This method is not guaranteed to stay around. "
"Please refer to colour module `rgb2hex` for rgb to hex conversion",
DeprecationWarning,
stacklevel=2,
)
return "#" + "".join("%02x" % round(255 * x) for x in rgb)


def hex_to_rgb(hex_code: str) -> np.ndarray:
warnings.warn(
"This method is not guaranteed to stay around. "
"Please refer to colour module `hex2rgb` for hex to rgb conversion",
DeprecationWarning,
stacklevel=2,
)
hex_part = hex_code[1:]
if len(hex_part) == 3:
hex_part = "".join([2 * c for c in hex_part])
Expand All @@ -322,6 +342,7 @@ def color_to_int_rgb(color: Color) -> np.ndarray:


def color_to_int_rgba(color: Color, opacity: float = 1.0) -> np.ndarray:

alpha_multiplier = np.vectorize(lambda x: int(x * opacity))

return alpha_multiplier(np.append(color_to_int_rgb(color), 255))
Expand Down Expand Up @@ -370,6 +391,7 @@ def random_color() -> Color:
return random.choice(list(ALL_COLORS.values()))



def get_shaded_rgb(
rgb: np.ndarray,
point: np.ndarray,
Expand Down