expyriment.misc.Colour

class expyriment.misc.Colour(colour)

Implements a class representing an RGB colour.

__init__(colour)

Create an RGB colour.

Parameters:
colourlist or tuple or str

the colour to be created as either an RGB tuple (e.g.[255, 0, 0]), a Hex triplet (e.g. “#FF0000”) or a colour name (e.g. “red”).

Notes

All methods in Expyriment that have a colour parameter require RGB colours. This class also allows RGB colours to be defined via HSV/HSL values (hue [0-360], saturation [0-100], value/lightness [0-100]).To do so, use the hsv or hls property.

static get_colour_names()

Get a dictionary of all known colour names.

property hex

Getter for colour in Hex format “#RRGGBB”.

property hsl

Getter for colour in HSL format [hue, saturation, lightness].

property hsv

Getter for colour in HSV format [hue, saturation, value].

static is_colour(value)

Check for valid colour value.

Parameters:
valueany type

the value to be checked

Returns:
validbool

whether the value is valid or not

static is_hex(value)

Check for valid Hex triplet value.

Parameters:
valuestring (e.g. “#FF0000”)

the value to be checked

Returns:
validbool

whether the value is valid or not

static is_hsl(value)

Check for valid HSL tuple value.

Parameters:
valueiterable of length 3 (e.g. [0, 100, 50])

the value to be checked

Returns:
validbool

whether the value is valid or not

static is_hsv(value)

Check for valid HSV tuple value.

Parameters:
valueiterable of length 3 (e.g. [0, 100, 100])

the value to be checked

Returns:
validbool

whether the value is valid or not

static is_name(value)

Check for valid colour name value.

Parameters:
valuestr (e.g. “red”)

the value to be checked

Returns:
validbool

whether the value is valid or not

static is_rgb(value)

Check for valid RGB tuple value.

Parameters:
valueiterable of length 3 (e.g. [255, 0, 0])

the value to be checked

Returns:
validbool

whether the value is valid or not

property name

Getter for colour name (if available).

property rgb

Getter for colour in RGB format [red, green, blue].