qualpal.Color
Python · python · 1.1.0
A color with various representations and conversions.
Color objects are immutable.
__init__
Source: qualpal/color.py
-> NoneCreate a Color from a hex string.
Parameters
hex_color : str
Hex color string in format #RRGGBB
Raises
ValueErrorIf hex_color is not a valid hex color string
from_rgb
Source: qualpal/color.py
-> Create a Color from RGB values.
Parameters
r, g, b : float
RGB values in range [0.0, 1.0]
Returns
Color
New Color object
from_hsl
Source: qualpal/color.py
-> Create a Color from HSL values.
Parameters
h : float
Hue in degrees [0.0, 360.0)
s : float
Saturation in range [0.0, 1.0]
l : float
Lightness in range [0.0, 1.0]
Returns
Color
New Color object
hex
Source: qualpal/color.py
-> Get hex representation.
Returns
str
Hex color string in format #rrggbb (lowercase)
rgb
Source: qualpal/color.py
-> Get RGB tuple in range [0.0, 1.0].
Returns
tuple[float, float, float]
RGB values as (r, g, b)
rgb255
Source: qualpal/color.py
-> Get RGB tuple in range [0, 255].
Returns
tuple[int, int, int]
RGB values as (r, g, b) integers
hsl
Source: qualpal/color.py
-> Get HSL tuple.
Returns
tuple[float, float, float]
HSL values as (h, s, l) where h is in degrees [0, 360) and s, l are in range [0.0, 1.0]
xyz
Source: qualpal/color.py
-> Get XYZ tuple.
Returns
tuple[float, float, float]
XYZ values as (x, y, z)
lab
Source: qualpal/color.py
-> Get Lab tuple.
Returns
tuple[float, float, float]
Lab values as (l, a, b) where l is in range [0, 100] and a, b are in range [-128, 127]
lch
Source: qualpal/color.py
-> Get LCH tuple.
Returns
tuple[float, float, float]
LCH values as (l, c, h) where l is in range [0, 100], c is chroma [0, ∞), and h is hue in degrees [0, 360)
distance
Source: qualpal/color.py
-> Calculate perceptual color difference to another color.
Parameters
other : Color | str
Another Color object or hex color string
metric : str
Distance metric to use. Options: - ‘ciede2000’ (default): CIEDE2000 metric - ‘din99d’: DIN99d metric - ‘cie76’: CIE76 (Euclidean distance in Lab space)
Returns
float
Perceptual color difference
Raises
ValueErrorIf metric is invalid or other color is not a valid color
Examples
>>> =
>>> =
>>>
86.61
>>>
32.77simulate_cvd
Source: qualpal/color.py
-> Simulate color vision deficiency on this color.
Parameters
cvd_type : str
Type of color vision deficiency: - ‘protan’: Protanomaly/Protanopia (red-weak/blind) - ‘deutan’: Deuteranomaly/Deuteranopia (green-weak/blind) - ‘tritan’: Tritanomaly/Tritanopia (blue-weak/blind)
severity : float
Severity of the deficiency in range [0, 1]: - 0.0: Normal vision (no change) - 1.0: Complete deficiency
Returns
Color
New Color object showing how this color appears with CVD
Raises
ValueErrorIf cvd_type is invalid or severity is out of range
Examples
>>> =
>>> =
>>> = 