Provide classes for representing RGB(A) and HSL(A) colors, as well as define common named colors.
Provide a base class for representing color values.
Color
A base class for representing color objects.
clamp
Clamp numeric values to be non-negative, an optionally, less than a given maximum.
value (float) – A number to clamp.
maximum (float, optional) – A max bound to to clamp to. If None, there is no upper bound, and values are only clamped to be non-negative. (default: None)
float
copy
Copy this color.
Subclasses must implement this method.
darken
Darken (reduce the luminance) of this color.
amount (float) – Amount to reduce the luminance by (clamped above zero)
from_hsl
Create a new color by converting from an HSL color.
value (HSL) – A color to convert from HSL
from_rgb
Create a new color by converting from an RGB color.
value (RGB) – A color to convert from RGB
RGB
lighten
Lighten (increase the luminance) of this color.
amount (float) – Amount to increase the luminance by (clamped above zero)
to_css
Return a CSS representation of this color.
str
to_hsl
Create a new HSL color by converting from this color.
HSL
to_rgb
Provide a class to represent colors with HSL (Hue, Saturation, Value).
Represent colors by specifying their Hue, Saturation, and lightness.
Alpha values may also optionally be provided. Otherwise, alpha values default to 1.
__init__
h (int) – The Hue, in [0, 360]
s (int) – The Saturation, in [0, 1]
l (int) – The lightness, in [0, 1]
a (float, optional) – An alpha value for this color in [0, 1] (default: 1.0)
Return a copy of this color value.
Copy an HSL color from another HSL color value.
value (HSL) – The HSL color to copy.
Create an HSL color from an RGB color value.
value (RGB) – The RGB color to convert.
Generate the CSS representation of this HSL color.
str, "hsl(...)" or "hsla(...)"
"hsl(...)"
"hsla(...)"
Return a HSL copy for this HSL color.
Return a corresponding RGB color for this HSL color.
Represent colors by specifying their Red, Green, and Blue channels.
r (int) – The value for the red channel in [0, 255]
g (int) – The value for the green channel in [0, 255]
b (int) – The value for the blue channel in [0, 255]
Create an RGB color from an HSL color value.
value (HSL) – The HSL color to convert.
Copy an RGB color from another RGB color value.
value (RGB) – The RGB color to copy.
Generate the CSS representation of this RGB color.
str, "rgb(...)" or "rgba(...)"
"rgb(...)"
"rgba(...)"
to_hex
Return a hex color string for this RGB color.
Any alpha value on this color is discarded, only hex color strings for the RGB components are returned.
str, "#RRGGBB"
"#RRGGBB"
Return a corresponding HSL color for this RGB color.
Return a RGB copy for this RGB color.
Organize CSS named colors into useful groups according to general hue.
black
CSS “Black” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
blue
CSS “Blue” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
brown
CSS “Brown” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
cyan
CSS “Cyan” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
green
CSS “Green” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
orange
CSS “Orange” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
pink
CSS “Pink” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
purple
CSS “Purple” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
red
CSS “Red” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
white
CSS “White” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
yellow
CSS “Yellow” Color Group as defined by https://www.w3schools.com/colors/colors_groups.asp
Provide the standard 147 CSS (X11) named colors.