Colouration
Colouration is a Python library for working with colours.
It unifies three representation of colour:
- RGB (red, green, blue)
- HSL (hue, saturation, lightness)
- HSV (hue, saturation, value)
Installation
pip install colouration
Usage
Colour
from colouration import Colour
default_arguments = Colour(
obj=None,
red=None, green=None, blue=None,
hexadecimal=None,
hue=None, saturation=None, lightness=None, value=None,
min_value=0.0, max_value=1.0,
name=None, id=None, scheme=None,
weight=1.0
)
red = Colour('#FF0000')
green = Colour(red=0, green=1, blue=0)
blue = Colour(red=0, green=0, blue=255, max_value=255)
literal_red = Colour('red')
print(f'is red equal to literal_red? {"yes" if red == literal_red else "no"}\n')
literal_red.print('by default the main colour is used for background\n')
red.print(string='red text\n', main_colour='text', secondary='auto')
red.print(string='the secondary colour is white when the main colour is dark and it is black otherwise.\n')
red.print(string='red on white\n', main_colour='text', secondary='white')
red.print(string='blue on red\n', secondary=Colour('blue'))
dark_red = red.darken(ratio=0.5)
dark_red.print(string='dark red\n')
light_red = red.lighten(ratio=0.8)
new_colour = red.increase_hue(0.2)
new_colour.print('hue increased by 0.2\n')
new_colour.red = 0.2
new_colour.print('setting red = 0.2 causes this.\n')
new_colour.hue = 0.8
new_colour.print('setting hue = 0.4 causes this.\n')
new_colour.value = 0.3
new_colour.print('setting value = 0.3 causes this.\n')
new_colour.lightness = 0.9
new_colour.print('setting lightness = 0.9 causes this.\n')
yellow = green + red
yellow.print(string='mixing green and red produces this.\n')
bluish = Colour(red=220, green=243, blue=255, max_value=255)
bluish.print(string=f'Colour finds the best name for itself: {bluish.name}.\n')
Scheme
Gradient