3
3
from __future__ import annotations
4
4
5
5
# logger = _config.logger
6
+ import colorsys
6
7
import random
7
8
from typing import Any , Sequence , Union
8
9
@@ -177,6 +178,9 @@ def named_lines_group(length, colors, names, text_colors, align_to_block):
177
178
RGBA_Array_Int : TypeAlias = "np.ndarray[Literal[4], np.dtype[ManimInt]]"
178
179
RGBA_Tuple_Int : TypeAlias = "tuple[int, int, int, int]"
179
180
181
+ HSV_Array_Float : TypeAlias = RGB_Array_Float
182
+ HSV_Tuple_Float : TypeAlias = RGB_Tuple_Float
183
+
180
184
ManimColorInternal : TypeAlias = "np.ndarray[Literal[4], np.dtype[ManimColorDType]]"
181
185
182
186
import re
@@ -355,6 +359,9 @@ def to_hex(self, with_alpha: bool = False) -> str:
355
359
if with_alpha :
356
360
tmp += f"{ int (self ._internal_value [3 ]* 255 ):02X} "
357
361
return tmp
362
+
363
+ def to_hsv (self ) -> HSV_Array_Float :
364
+ return colorsys .rgb_to_hsv (* self .to_rgb ())
358
365
359
366
def invert (self , with_alpha = False ) -> ManimColor :
360
367
return ManimColor (1.0 - self ._internal_value , with_alpha )
@@ -381,6 +388,15 @@ def from_rgba(
381
388
@classmethod
382
389
def from_hex (cls , hex : str , alpha : float = 1.0 ) -> ManimColor :
383
390
return cls (hex , alpha )
391
+
392
+ @classmethod
393
+ def from_hsv (
394
+ cls ,
395
+ hsv : HSV_Array_Float | HSV_Tuple_Float ,
396
+ alpha : float = 1.0
397
+ ) -> ManimColor :
398
+ rgb = colorsys .hsv_to_rgb (* hsv )
399
+ return cls (rgb , alpha )
384
400
385
401
@classmethod
386
402
def parse (
0 commit comments