# Colour class¶

class colourettu.Colour(mycolour='#FFF', normalized_rgb=False)[source]

Base class for dealing with colours.

Parameters: mycolour (str, list, or tuple) – string of hex representation of colour you are creating, or a 3 item list or tuple of the red, green, and blue channels of the colour you are creating. Default is “#FFF” (white). normalized_rgb (bool) – whether the values for the red, green, and blue channels are normalized (i.e. values scaled from 0 to 1) or not (i.e. values scaled from 0 to 255). Default is False.

Colours are created by calling the Colour class. Colour values can be provided via 3 or 6 digit hex notation, or providing a list or a tuple of the Red, Green, and Blue values (as integers, if normalized_rgb=False, or as floating numbers between 0 and 1 if normalized_rgb=True).

import colourettu
from colourettu import Colour

c1 = Colour()        # defaults to #FFF
c2 = Colour("#eee")  # equivalent to #EEEEEE
c3 = Colour("#456bda")
c4 = Colour([3, 56, 129])
c5 = Colour((63, 199, 233))
c6 = Colour([0.242, 0.434, 0.165], normalized_rgb=True)


The value of each channel can be pulled out:

>>> c4.red()
3
>>> c4.green()
56
>>> c4.blue()
129


You can also get the colour back as either a hex value, or a rgb tuple:

>>> c2.hex()
'#EEEEEE'
>>> c2.rgb()
(238, 238, 238)


Colours are considered equal is the values of the R, G, and B channels match.

>>> c1 == c2
False
>>> c2 == Color([238, 238, 238])
True

blue()[source]

Returns the value of the blue channel of the Colour.

Returns: value of the blue channel of the colour int
contrast(myothercolour)[source]

Calls the contrast() on the colour defined.

green()[source]

Returns the value of the green channel of the Colour.

Returns: value of the green channel of the colour int
hex()[source]

Returns the HTML-style hex code for the Colour.

Returns: the colour as a HTML-sytle hex string str
luminance()[source]

Calls the luminance() on the colour defined.

normalized_rgb()[source]

Returns a tuples of the normalized values of the red, green, and blue channels of the Colour.

Returns: the rgb values of the colour (with values normalized between 0.0 and 1.0) tuple

Note

Uses the formula:

$r_{norm} = \begin{cases} \frac{r_{255}}{12.92}\ \qquad &\text{if r_{255} \le 0.03928} \\ \left(\frac{r_{255} + 0.055}{1.055}\right)^{2.4} \quad &\text{otherwise} \end{cases}$

Source

red()[source]

Returns the value of the red channel of the Colour.

Returns: value of the red channel of the colour int
rgb()[source]

Returns a tuples of the values of the red, green, and blue channels of the Colour.

Returns: the rgb values of the colour (with values between 0 and 255) tuple