Skip to main content

Python library for working with colours

Project description

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
)

# you can use the rgb hexadecimal code to create a Colour object
red = Colour('#FF0000')

# you can enter red, green, and blue as separate values
green = Colour(red=0, green=1, blue=0)

# max value is 1 by default but other values can be used too
blue = Colour(red=0, green=0, blue=255, max_value=255)

# and you can use colour names 
literal_red = Colour('red')
print(f'is red equal to literal_red? {"yes" if red == literal_red else "no"}\n')

# you can print with it
literal_red.print('by default the main colour is used for background\n')

# to use the colour as the text colour you should use the main_colour argument
red.print(string='red text\n', main_colour='text', secondary='auto') # secondary='auto' is default

# the secondary colour is white when the main colour is dark and it is black otherwise
red.print(string='the secondary colour is white when the main colour is dark and it is black otherwise.\n')

# you can choose a secondary colour
red.print(string='red on white\n', main_colour='text', secondary='white')

# you can use string or a Colour object
red.print(string='blue on red\n', secondary=Colour('blue'))

# you can darken or lighten a colour
dark_red = red.darken(ratio=0.5)
dark_red.print(string='dark red\n') 

# ratio can be between 0 and 1
light_red = red.lighten(ratio=0.8) 

# you can change the hue of a colour
new_colour = red.increase_hue(0.2)
new_colour.print('hue increased by 0.2\n')

# you can assign a new hue, lightness, value, red, green, or blue too
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')

# you can mix colours by adding them together
yellow = green + red
yellow.print(string='mixing green and red produces this.\n')

# Colour finds the best name for itself
bluish = Colour(red=220, green=243, blue=255, max_value=255) # max_value is 1 by default
bluish.print(string=f'Colour finds the best name for itself: {bluish.name}.\n')

Scheme

Gradient

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colouration-2020.4.6.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

colouration-2020.4.6-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file colouration-2020.4.6.tar.gz.

File metadata

  • Download URL: colouration-2020.4.6.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for colouration-2020.4.6.tar.gz
Algorithm Hash digest
SHA256 11eb6ea3ec6f960be48fb80bbab5e2b36d861666386ff0e85d63cbdc1ef27c24
MD5 bf4cd09d1d78e789f9f25eb5c2bd1be9
BLAKE2b-256 e8185756cdbed652d6f5ea15a5c5ae69c548a3d8bee831a5d695dbbf041ee6fb

See more details on using hashes here.

File details

Details for the file colouration-2020.4.6-py3-none-any.whl.

File metadata

  • Download URL: colouration-2020.4.6-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for colouration-2020.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b94d2c37dbcb208913e9b00d00a5ad1a0d032ef226ed8e26d3e10331de4324b7
MD5 61fbdbaec7b1119973b1bcbededf27dd
BLAKE2b-256 b8da7f3e87f271234b9c0152d91fde5366baa32eaee86b922a3dcedb9cf03817

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page