Colors API¶
The base class for colors is the following:
- class thcolor.colors.Color(alpha=1.0)¶
Class representing a color within thcolor.
- Parameters
alpha (
float
) – Value foralpha
.
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- css()¶
Get the CSS color descriptions.
Includes older CSS specifications compatibility, as a sequence of strings.
For example:
>>> SRGBColor.frombytes(18, 52, 86, 0.82).css() ... ("#123456", "rgba(18, 52, 86, 82%)")
- Return type
Sequence
[str
]
- darker(by=0.1)¶
Get a darker version of the given color.
- Parameters
by (
float
) – Percentage by which the color should be darker.- Return type
- desaturate(by=0.1)¶
Get a less saturated version of the given color.
- Parameters
by (
float
) – Percentage by which the color should be desaturated.- Return type
- classmethod fromtext(expr, decoder=None)¶
Create a color from a string.
- Parameters
expr (
str
) – The expression to decode.- Return type
- lighter(by=0.1)¶
Get a lighter version of the given color.
- Parameters
by (
float
) – Percentage by which the color should be lighter.- Return type
- replace(**properties)¶
Get the color with the given properties replaced.
For changing the alpha on an RGB color:
>>> SRGBColor(.1, .2, .3).replace(alpha=.5) ... SRGBColor(red=0.1, green=0.2, blue=0.3, alpha=0.5)
For changing the lightness on an HSL color:
>>> HSLColor(DegreesAngle(270), .5, 1).replace(lightness=.2) ... HSLColor(hue=DegreesAngle(degrees=270.0), saturation=0.5, ... lightness=0.2, alpha=1.0)
- Parameters
properties – Properties to change from the original color.
- Return type
Subclasses are the following:
- class thcolor.colors.CMYKColor(cyan, magenta, yellow, black, alpha=1.0)¶
A color expressed using its CMYK channels’ intensities.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property black¶
Black channel intensity between 0.0 and 1.0.
- property cyan¶
Cyan channel intensity between 0.0 and 1.0.
- property magenta¶
Magenta channel intensity between 0.0 and 1.0.
- property yellow¶
Yellow channel intensity between 0.0 and 1.0.
- class thcolor.colors.HSLColor(hue, saturation, lightness, alpha=1.0)¶
A color expressed using its hue, saturation and lightness components.
- Parameters
saturation (
float
) – Value forsaturation
.lightness (
float
) – Value forlightness
.alpha (
float
) – Value foralpha
.
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property hue: thcolor.angles.Angle¶
The hue, as an angle.
- Return type
- property lightness: float¶
The lightness, between 0.0 and 1.0.
- Return type
float
- property saturation: float¶
The saturation, between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.HSVColor(hue, saturation, value, alpha=1.0)¶
A color expressed using its hue, saturation and value components.
- Parameters
saturation (
float
) – Value forsaturation
.value (
float
) – Value forvalue
.alpha (
float
) – Value foralpha
.
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property hue: thcolor.angles.Angle¶
The hue, as an angle.
- Return type
- property saturation: float¶
The saturation, between 0.0 and 1.0.
- Return type
float
- property value: float¶
The value, between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.HWBColor(hue, whiteness=0.0, blackness=0.0, alpha=1.0)¶
A color expressed using its hue, whiteness and blackness components.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property blackness: float¶
The blackness, as a value between 0.0 and 1.0.
- Return type
float
- property hue: thcolor.angles.Angle¶
The hue, as an angle.
- Return type
- property whiteness: float¶
The whiteness, as a value between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.LABColor(lightness, a, b, alpha=1.0)¶
A color expressed using its CIELAB color space cartesian coordinates.
- Parameters
- property a: float¶
The A axis value in the Lab colorspace.
- Return type
float
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property b: float¶
The B axis value in the Lab colorspace.
- Return type
float
- property lightness: float¶
The CIE lightness.
Similar to the lightness in the HSL representation. Represented as a float between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.LCHColor(lightness, chroma, hue, alpha=1.0)¶
A color expressed using its CIELAB color space polar coordinates.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property chroma: float¶
The chroma.
Represented as a positive number theoretically unbounded.
- Return type
float
- property hue: thcolor.angles.Angle¶
The hue, as an angle.
- Return type
- property lightness: float¶
The CIE lightness.
Similar to the lightness in the HSL representation. Represented as a float between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.SRGBColor(red, green, blue, alpha=1.0)¶
A color expressed using its channel intensities in the sRGB profile.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- asbytes()¶
Get the red, blue and green bytes.
- Return type
Tuple
[int
,int
,int
]
- property blue: float¶
The intensity of the blue channel.
Represented as a float between 0.0 (dark) and 1.0 (light).
- Return type
float
- classmethod frombytes(red, green, blue, alpha=1.0)¶
Get an sRGB color from colors using values between 0 and 255.
- Return type
- classmethod fromnetscapecolorname(name)¶
Get an sRGB color from a Netscape color name.
- Return type
- property green: float¶
The intensity of the green channel.
Represented as a float between 0.0 (dark) and 1.0 (light).
- Return type
float
- property red: float¶
The intensity of the red channel.
Represented as a float between 0.0 (dark) and 1.0 (light).
- Return type
float
- class thcolor.colors.XYZColor(x, y, z, alpha=1.0)¶
A color expressed using its CIEXYZ color space coordinates.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property x: float¶
The CIE X component, between 0.0 and 1.0.
- Return type
float
- property y: float¶
The CIE Y component, between 0.0 and 1.0.
- Return type
float
- property z: float¶
The CIE Z component, between 0.0 and 1.0.
- Return type
float
- class thcolor.colors.YIQColor(y, i, q, alpha=1.0)¶
A color expressed using its YIQ components.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property i: float¶
The orange-blue range value.
- Return type
float
- property q: float¶
The purple-green range value.
- Return type
float
- property y: float¶
The luma.
- Return type
float
- class thcolor.colors.YUVColor(y, u, v, alpha=1.0)¶
A color expressed using its YUV components.
- Parameters
- property alpha: float¶
The alpha component value.
Represented as a float varying between 0.0 (invisible) and 1.0 (opaque).
- Return type
float
- property u: float¶
The U chrominance.
- Return type
float
- property v: float¶
The V chrominance.
- Return type
float
- property y: float¶
The luma.
- Return type
float