Named colors in Python
Project description
nc solves two problems - color to string, and string to color.
In the simplest use, it’s a collection of about 1700 colors, some scraped from the Wikipedia (which includes some very strange colors), with a neat API.
For more precise use, color collections can be put together from schemes built into nc (currently html, juce, pwg, wikipedia, x11), and from custom color schemes created by the user.
Install nc from the command line using pip:
pip3 install nc
EXAMPLES:
import nc
for c in nc.red, nc.light_green, nc.DarkGrey, nc['PUCE']:
print(c, '=', *c)
# Prints:
# Red = 255 0 0
# Light green = 144 238 144
# Dark grey = 85 85 85
# Puce = 204 136 153
# Colors have red, green, blue or r, g, b components
assert nc.yellow.red == nc.yellow.r == 0
assert nc.yellow.green == nc.yellow.g == 255
assert nc.yellow.blue == nc.yellow.b == 255
# Lots of ways to reach colors
assert nc.black == nc(0, 0, 0) == nc('0, 0, 0') == nc('(0, 0, 0)') == nc(0)
# ``nc`` looks like a dict
assert nc.red == nc['red'] == nc['RED']
for name, color in nc.items():
print(name, '=', *color)
# Prints:
# Absolute Zero = 0 72 186
# Acid green = 176 191 26
# Aero = 124 185 232
# ... many more
# closest() function
from random import randrange
for i in range(8):
c1 = randrange(256), randrange(256), randrange(256)
c2 = nc.closest(c1)
print(c1, 'is closest to', c2, *c2)
# Prints:
# (193, 207, 185) is closest to Honeydew 3 = 193 205 193
# (181, 162, 188) is closest to Lilac = 200 162 200
# (122, 110, 250) is closest to Slate blue 1 = 131 111 255
# (56, 218, 180) is closest to Turquoise = 64 224 208
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nc-0.9.3.tar.gz
(32.1 kB
view details)
Built Distribution
nc-0.9.3-py3-none-any.whl
(45.3 kB
view details)
File details
Details for the file nc-0.9.3.tar.gz
.
File metadata
- Download URL: nc-0.9.3.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6ecaa03672b886f58fd2ab5874c81b565a5cfdf544a8035de290dcc9436b900 |
|
MD5 | 2ca9b965dbd090912d0dcc8a28339823 |
|
BLAKE2b-256 | 49289c84416f3895a74b2af1a483d15ba32b35ef126d178c9125c8104111381d |
File details
Details for the file nc-0.9.3-py3-none-any.whl
.
File metadata
- Download URL: nc-0.9.3-py3-none-any.whl
- Upload date:
- Size: 45.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd672c755cc315757d5519956896ec7922b0f0c1e347f639ec6a0a927c699360 |
|
MD5 | 49ea6ab549cb8a70d0adef6ae861a01d |
|
BLAKE2b-256 | 7fee78807c5c69501a7d613f3739c438c0506be83c50502d5acb5c8c80189921 |