Reference¶
Python utilities for colors
- class pigment.Color(red: int, green: int, blue: int)[source]¶
Represents a color
- Parameters
red (
int
) – The color’s red RGB component (0-255)green (
int
) – The color’s green RGB component (0-255)blue (
int
) – The color’s blue RGB component (0-255)
- property cmyk¶
The color as a CMYK tuple
Cyan (0-100)
Magenta (0-100)
Yellow (0-100)
Key/Black (0-100)
- classmethod from_css_name(css_color: str)[source]¶
Gets a color from a CSS color name
- Parameters
css_color (
str
) – The name of the CSS color- Returns
- property hex_code¶
The color’s hex code
- property hls¶
The color as an HLS tuple
Hue: color (0-360)
Lightness: amount of white vs. color (0-100)
Saturation: amount of gray vs. color (0-100)
- property hsv¶
The color as an HSV tuple
Hue: color (0-360)
Saturation: amount of gray vs. color (0-100)
Value: amount of black vs. color (0-100)
- property hue¶
The color’s hue (0-360)
- classmethod random(red: tuple = (0, 255), green: tuple = (0, 255), blue: tuple = (0, 255))[source]¶
Generates a random color
This works by generating random red, green, and blue values using
random.randint()
from the standard library using the min/max values specified if any- Parameters
red (
tuple
) – The two arguments to pass for the red valuegreen (
tuple
) – The two arguments to pass for the green valueblue (
tuple
) – The two arguments to pass for the blue value
- Returns
- property rgb¶
The color as an RGB tuple
Red (0-255)
Green (0-255)
Blue (0-255)
- pigment.blend(color1: pigment.Color, color2: pigment.Color) pigment.Color [source]¶
Blends two colors together
- pigment.normalize_hex(hex_code: str) str [source]¶
Normalizes a hex color code
Removes the leading
#
if there is one, expands 3-character hex codes, and lowercases the hex code- Parameters
hex_code (
str
) – A hex code to normalize- Returns
The normalized hex code
- Return type
str
- Raises
WrongLengthError – The provided hex code had the wrong length