The Color class.
Color
Color(r= 255.0 , g= None , b= None , a= 255.0 )
An RGBA colour with channels in 0-255.
Channels are floats and are not clamped (see clamp). A Color can be passed anywhere a colour is accepted, such as fill(c) and background(c), and iterates as (r, g, b, a). The named colours (Color.RED and friends) hand out a fresh Color on every access, so changing one, for example Color.RED.hue = 10, never alters the constant.
Color("tomato") and Color("#ff6246") read a colour string (see fill), with an optional alpha as the second argument.
Parameters
r
float | str
Red, or the gray level when g and b are omitted, or a colour string.
255.0
g
float | None
Green, or the alpha when only r and g are given.
None
b
float | None
Blue.
None
a
float
Alpha.
255.0
Attributes
r
Red, 0-255.
g
Green, 0-255.
b
Blue, 0-255.
a
Alpha, 0-255.
Methods
clamp
Returns a copy with every channel clamped to 0-255.
from_hex
Makes a Color from 0xRRGGBB or "#rrggbb[aa]".
from_hsb
Makes a Color from hue, saturation and brightness.
invert
Returns the inverted colour as a new Color.
lerp
Returns the colour amount of the way to other, as a new Color.
clamp
Returns a copy with every channel clamped to 0-255.
Returns
Color
The clamped Color; this one does not change.
from_hex
Color.from_hex(hex_value, a= None )
Makes a Color from 0xRRGGBB or "#rrggbb[aa]".
Parameters
hex_value
int | str
The colour as an integer 0xRRGGBB, or a string "#rrggbb" or "#rrggbbaa".
required
a
float | None
Alpha, 0-255; None keeps the string’s alpha (255 without one).
None
Raises
ValueError
The string is not "#rrggbb" or "#rrggbbaa".
from_hsb
Color.from_hsb(hue, saturation, brightness, a= 255.0 )
Makes a Color from hue, saturation and brightness.
Parameters
hue
float
Hue, 0-255 (0 and 255 are both red; 85 is green, 170 is blue).
required
saturation
float
Saturation, 0-255.
required
brightness
float
Brightness, 0-255.
required
a
float
Alpha, 0-255.
255.0
invert
Returns the inverted colour as a new Color.
Returns
Color
A Color with r, g and b inverted and the same alpha; this one does not change.
lerp
Color.lerp(other, amount)
Returns the colour amount of the way to other, as a new Color.
Neither colour changes, like kiln.lerp. Alpha is interpolated too.
Parameters
other
Color
The colour at amount 1.
required
amount
float
Position between the two, 0 to 1 (not clamped).
required
Returns
Color
A new interpolated Color.