Cooper Hewitt's Python tools for wrangling colours.
import cooperhewitt.swatchbook as sb
print sb.closest('css3', '#7c5d5c')
# Would print:
# ('#696969', 'dimgrey')
import cooperhewitt.swatchbook as sb
palette = sb.load_palette('crayola')
print palette.name('#a8e4a0')
# Would print:
# Granny Smith Apple
import cooperhewitt.swatchbook.crayola
palette = cooperhewitt.swatchbook.crayola.palette()
# See below for object methods
Assuming:
palette = cooperhewitt.swatchbook.naturalcolorsystem.palette()
print palette.source()
# Would print:
# naturalcolorsystem
print palette.colours()
# Would print
# {'#009f6b': {'name': 'green'}, '#c40233': {'name': 'red'}, '#000000': {'name': 'black'}, '#0087bd': {'name': 'blue'}, '#ffd300': {'name': 'yellow'}, '#ffffff': {'name': 'white'}}
Just a helper wrapper around palette.colours()
for Americans
print palette.hex('red')
# Would print:
# #c40233
print palette.name('#ffd300')
# Would print:
# yellow
Return colours and source as a Python dict object.
print palette.as_dict()
# Would print:
# {'colours': {'#009f6b': {'name': 'green'}, '#c40233': {'name': 'red'}, '#000000': {'name': 'black'}, '#0087bd': {'name': 'blue'}, '#ffd300': {'name': 'yellow'}, '#ffffff': {'name': 'white'}}, 'source': 'naturalcolorsystem'}
Return the results of palette.as_dict
serialized as JSON.
print palette.as_json(indent=2)
# Would print:
# {
# "colours": {
# "#009f6b": {
# "name": "green"
# },
# "#c40233": {
# "name": "red"
# },
# "#000000": {
# "name": "black"
# },
# "#0087bd": {
# "name": "blue"
# },
# "#ffd300": {
# "name": "yellow"
# },
# "#ffffff": {
# "name": "white"
# }
# },
# "source": "naturalcolorsystem"
# }
Return the hex colours sorted.
print palette.sorted()
# Would print:
# ['#ffd300', '#009f6b', '#0087bd', '#c40233', '#000000', '#ffffff']
print palette.closest('#7c5d5c')
# Would print
# ('#c40233', 'red')
The following colour palettes are supported: