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], Color], alpha: Optional[float] = None)[source]¶ - Overview:
Color utility object.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('red') # from name >>> c <Color red> >>> str(c) # hex format '#ff0000' >>> (c.rgb.red, c.rgb.green, c.rgb.blue) # rgb format (1.0, 0.0, 0.0) >>> (c.hls.hue, c.hls.lightness, c.hls.saturation) # hls format (0.0, 0.5, 1.0) >>> (c.hsv.hue, c.hsv.value, c.hsv.saturation) # hsv format (0.0, 1.0, 1.0)
>>> c1 = Color('#56a3f0') # from hex >>> c1 <Color #56a3f0> >>> str(c1) # hex format '#56a3f0' >>> (c1.rgb.red, c1.rgb.green, c1.rgb.blue) # rgb format (0.33725490196078434, 0.6392156862745098, 0.9411764705882353) >>> (c1.hls.hue, c1.hls.lightness, c1.hls.saturation) # hls format (0.5833333333333334, 0.6392156862745098, 0.8369565217391304) >>> (c1.hsv.hue, c1.hsv.value, c1.hsv.saturation) # hsv format (0.5833333333333334, 0.9411764705882353, 0.6416666666666666)
>>> c2 = Color('#56a3f077') # from hex >>> c2 <Color #56a3f0, alpha: 0.467> >>> c2.alpha # alpha value 0.4666666666666667 >>> str(c2) # hex format '#56a3f077'
-
__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], Color], 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
¶ Alpha value, which means the transparent ratio (within \(\left[0.0, 1.0\right]\)).
- :: note::
Setter is available.
-
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. See
HLSColorProxy
.- Returns:
proxy (
HLSColorProxy
): Hls color proxy.
-
property
hsv
¶ - Overview:
Get hsv color system based color proxy. See
HSVColorProxy
.- Returns:
proxy (
HSVColorProxy
): Hsv color proxy.
-
property
rgb
¶ - Overview:
Get rgb color system based color proxy. See
RGBColorProxy
.- Returns:
proxy (
RGBColorProxy
): Rgb color proxy.
RGBColorProxy¶
-
class
hbutils.color.model.
RGBColorProxy
(this: hbutils.color.model.Color, r: hbutils.color.model.GetSetProxy, g: hbutils.color.model.GetSetProxy, b: hbutils.color.model.GetSetProxy)[source]¶ - Overview:
Color proxy for RGB space.
-
__init__
(this: hbutils.color.model.Color, r: hbutils.color.model.GetSetProxy, g: hbutils.color.model.GetSetProxy, b: hbutils.color.model.GetSetProxy)[source]¶ Constructor of
RGBColorProxy
.- Parameters:
this – Original color object.
r – Get-set proxy for red.
g – Get-set proxy for green.
b – Get-set proxy for blue.
-
__iter__
()[source]¶ Iterator for this proxy.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> r, g, b = c.rgb >>> print(r, g, b) 0.0 0.5019607843137255 0.0
-
__repr__
()[source]¶ Representation format.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> c.rgb <RGBColorProxy red: 0.000, green: 0.502, blue: 0.000>
-
property
blue
¶ Blue value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.-
property
green
¶ Green value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.-
property
red
¶ Red value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.HLSColorProxy¶
-
class
hbutils.color.model.
HLSColorProxy
(this: hbutils.color.model.Color, h: hbutils.color.model.GetSetProxy, l: hbutils.color.model.GetSetProxy, s: hbutils.color.model.GetSetProxy)[source]¶ - Overview:
Color proxy for HLS space.
-
__init__
(this: hbutils.color.model.Color, h: hbutils.color.model.GetSetProxy, l: hbutils.color.model.GetSetProxy, s: hbutils.color.model.GetSetProxy)[source]¶ Constructor of
HLSColorProxy
.- Parameters:
this – Original color object.
h – Get-set proxy for hue.
l – Get-set proxy for lightness.
s – Get-set proxy for saturation.
-
__iter__
()[source]¶ Iterator for this proxy.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> h, l, s = c.hls >>> print(h, l, s) 0.3333333333333333 0.25098039215686274 1.0
-
__repr__
()[source]¶ Representation format.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> c.hls <HLSColorProxy hue: 0.333, lightness: 0.251, saturation: 1.000>
-
property
hue
¶ Hue value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.-
property
lightness
¶ Lightness value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.-
property
saturation
¶ Saturation value (within \(\left[0.0, 1.0\right]\)).
Note
Setter is available, the change will affect the
Color
object.HSVColorProxy¶
-
class
hbutils.color.model.
HSVColorProxy
(this: hbutils.color.model.Color, h: hbutils.color.model.GetSetProxy, s: hbutils.color.model.GetSetProxy, v: hbutils.color.model.GetSetProxy)[source]¶ - Overview:
Color proxy for HSV space.
-
__init__
(this: hbutils.color.model.Color, h: hbutils.color.model.GetSetProxy, s: hbutils.color.model.GetSetProxy, v: hbutils.color.model.GetSetProxy)[source]¶ Constructor of
HSVColorProxy
.- Parameters:
this – Original color object.
h – Get-set proxy for hue.
s – Get-set proxy for saturation.
v – Get-set proxy for value.
-
__iter__
()[source]¶ Iterator for this proxy.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> h, s, v = c.hsv >>> print(h, s, v) 0.3333333333333333 1.0 0.5019607843137255
-
__repr__
()[source]¶ Representation format.
- Examples::
>>> from hbutils.color import Color >>> >>> c = Color('green') >>> c.hsv <HSVColorProxy hue: 0.333, saturation: 1.000, value: 0.502>
-
property
brightness
¶ Alias for
value
.
-
class
Other Versions v: v0.9.2- Tags
- v0.0.1
- v0.1.0
- v0.1.1
- v0.10.0
- v0.10.1
- v0.2.0
- v0.3.0
- v0.3.1
- v0.3.2
- v0.3.3
- v0.4.0
- v0.4.1
- v0.4.2
- v0.4.3
- v0.4.4
- v0.4.5
- v0.4.6
- v0.4.7
- v0.5.0
- v0.5.1
- v0.5.2
- v0.6.0
- v0.6.1
- v0.6.10
- v0.6.11
- v0.6.12
- v0.6.13
- v0.6.14
- v0.6.2
- v0.6.3
- v0.6.4
- v0.6.5
- v0.6.6
- v0.6.7
- v0.6.8
- v0.6.9
- v0.7.0
- v0.7.1
- v0.7.2
- v0.7.3
- v0.7.4
- v0.7.5
- v0.7.6
- v0.8.0
- v0.8.1
- v0.8.2
- v0.8.3
- v0.8.4
- v0.8.5
- v0.8.6
- v0.9.0
- v0.9.1
- v0.9.2
- v0.9.3
-
property
-
property
-
class
-
property
-
property