hbutils.color.model¶
- Overview:
Color model, include rgb, hsv, hls color system.
More color system will be supported soon.
Color¶
-
class
hbutils.color.model.
Color
(c: Union[str, Tuple[float, float, float]], alpha: Optional[float] = None)[source]¶ - Overview:
Color utility object.
-
__eq__
(other)[source]¶ - Overview:
Get equality between colors.
- Arguments:
other: Another object.
- Returns:
equal (
bool
): Equal or not.
-
__getstate__
() → Tuple[float, float, float, Optional[float]][source]¶ - Overview:
Dump color as pickle object.
- Returns:
info (
Tuple[float, float, float, Optional[float]]
): Dumped data object.
-
__hash__
()[source]¶ - Overview:
Get hash value of current object.
- Returns:
hash (
int
): Hash value of current color.
-
__init__
(c: Union[str, Tuple[float, float, float]], alpha: Optional[float] = None)[source]¶ - Overview:
Constructor of
Color
.- Arguments:
c (
Union[str, Tuple[float, float, float]]
): Color value, can be hex string value or tuple rgb value.alpha: (
Optional[float]
): Alpha value of color, default is None which means no alpha value.
-
__setstate__
(v: Tuple[float, float, float, Optional[float]])[source]¶ - Overview:
Load color from pickle object.
- Args:
v (
Tuple[float, float, float, Optional[float]]
): Dumped data object.
-
property
alpha
¶ - Overview:
Get value of alpha.
- Returns:
alpha (
Optional[float]
): Alpha value.
-
classmethod
from_hex
(hex_: str) → hbutils.color.model.Color[source]¶ - Overview:
Load color from hexadecimal rgb string.
- Arguments:
hex_ (
str
): Hexadecimal string, maybe starts with#
.
- Returns:
color (
Color
): Color object.
-
classmethod
from_hls
(h: float, l: float, s: float, alpha: Optional[float] = None) → hbutils.color.model.Color[source]¶ - Overview:
Load color from hls system.
- Arguments:
h (
float
): Hue value, should be a float value in \(\left[0, 1\right)\).l (
float
): Lightness value, should be a float value in \(\left[0, 1\right]\).s (
float
): Saturation value, should be a float value in \(\left[0, 1\right]\).alpha (
Optional[float]
): Alpha value, should be a float value in \(\left[0, 1\right]\), default is None which means no alpha value is used.
- Returns:
color (
Color
): Color object.
-
classmethod
from_hsv
(h, s, v, alpha=None) → hbutils.color.model.Color[source]¶ - Overview:
Load color from hsv system.
- Arguments:
h (
float
): Hue value, should be a float value in \(\left[0, 1\right)\).s (
float
): Saturation value, should be a float value in \(\left[0, 1\right]\).v (
float
): Brightness (value) value, should be a float value in \(\left[0, 1\right]\).alpha (
Optional[float]
): Alpha value, should be a float value in \(\left[0, 1\right]\), default is None which means no alpha value is used.
- Returns:
color (
Color
): Color object.
-
classmethod
from_rgb
(r, g, b, alpha=None) → hbutils.color.model.Color[source]¶ - Overview:
Load color from rgb system.
- Arguments:
r (
float
): Red value, should be a float value in \(\left[0, 1\right)\).g (
float
): Green value, should be a float value in \(\left[0, 1\right]\).b (
float
): Blue value, should be a float value in \(\left[0, 1\right]\).alpha (
Optional[float]
): Alpha value, should be a float value in \(\left[0, 1\right]\), default is None which means no alpha value is used.
- Returns:
color (
Color
): Color object.
-
property
hls
¶ - Overview:
Get hls color system based color proxy.
- Returns:
proxy (
HLSColorProxy
): Hls color proxy.
-
property
hsv
¶ - Overview:
Get hsv color system based color proxy.
- Returns:
proxy (
HSVColorProxy
): Hsv color proxy.
-
property
rgb
¶ - Overview:
Get rgb color system based color proxy.
- Returns:
proxy (
RGBColorProxy
): Rgb color proxy.