Color
- class compas.colors.Color(red, green, blue, alpha=1.0, **kwargs)[source]
Bases:
Data
Class for working with colors.
- Parameters
red (float) – The red component in the range of 0-1.
green (float) – The green component in the range of 0-1.
blue (float) – The blue component in the range of 0-1.
alpha (float, optional) – Transparency setting. If
alpha = 0.0
, the color is fully transparent. Ifalpha = 1.0
, the color is fully opaque.
- Other Parameters
**kwargs (dict, optional) – See
Data
for more information.- Attributes
r (float) – Red component of the color in RGB1 color space.
g (float) – Green component of the color in RGB1 color space.
b (float) – Blue component of the color in RGB1 color space.
rgb (tuple[float, float, float]) – RGB1 color tuple, with components in the range 0-1.
rgb255 (tuple[int, int, int]) – RGB255 color tuple, with components in the range 0-255.
hex (str) – Hexadecimal color string.
hls (tuple[float, float, float]) – Hue, Lightness, Saturation.
hsv (tuple[float, float, float]) – Hue, Saturation, Value / Brightness.
lightness (float) – How much white the color appears to contain. This is the “Lightness” in HLS. Making a color “lighter” is like adding more white.
brightness (float) – How well-lit the color appears to be. This is the “Value” in HSV. Making a color “brighter” is like shining a stronger light on it, or illuminating it better.
is_light (bool) – If True, the color is considered light.
Examples
>>> Color(1, 0, 0) Color(1.0, 0.0, 0.0, 1.0) >>> Color.red() Color(1.0, 0.0, 0.0, 1.0) >>> Color(1, 0, 0) == Color.red() True
>>> Color.magenta() Color(1.0, 0.0, 1.0, 1.0) >>> Color.lime() Color(0.5, 1.0, 0.0, 1.0) >>> Color.navy() Color(0.0, 0.0, 0.5, 1.0) >>> Color.olive() Color(0.5, 0.5, 0.0, 1.0)
>>> Color.lime().is_light True >>> Color.navy().is_light False
Methods
Construct the color azure.
Construct the color black.
Construct the color blue.
Construct the color brown.
Construct the color cyan.
Darken the color.
Return a darkened copy of the color.
Desaturate the color by a given percentage.
Return a desaturated copy of the color.
Construct an object of this type from the provided data.
Construct a color from a hexadecimal color value.
Construct a color from Hue, Luminance, and Saturation.
Construct a color from Hue, Saturation, and Value.
Construct a color from a single number in the range 0-1.
Construct a color from a name in the extended color table of HTML/CSS/SVG.
Construct a color from RGB255 components.
Construct a color from components in the YIQ color space.
Construct a color from components in the YUV color space.
Construct the color green.
Construct the color grey.
Invert the current color wrt to the RGB color circle.
Return an inverted copy of the color.
Verify that the color is in hexadecimal format.
Verify that the color is in the RGB 1 color space.
Verify that the color is in the RGB 255 color space.
Lighten the color.
Return a lightened copy of the color.
Construct the color lime (or chartreuse green).
Construct the color magenta.
Construct the color maroon.
Construct the color mint (or spring green).
Construct the color navy.
Construct the color olive.
Construct the color orange.
Construct the color pink.
Construct the color purple.
Construct the color red.
Saturate the color by a given percentage.
Return a saturated copy of the color.
Construct the color silver.
Construct the color teal.
Construct the color violet.
Construct the color white.
Construct the color yellow.
Inherited Methods
Make an independent copy of the data object.
Construct an object from serialized data contained in a JSON file.
Construct an object from serialized data contained in a JSON string.
Convert an object to its native data representation.
Serialize the data representation of an object to a JSON file.
Serialize the data representation of an object to a JSON string.
Validate the object's data against its data schema.
Validate the object's data against its json schema.