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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
nc-0.9.2-py3-none-any.whl
(44.4 kB
view details)
File details
Details for the file nc-0.9.2-py3-none-any.whl
.
File metadata
- Download URL: nc-0.9.2-py3-none-any.whl
- Upload date:
- Size: 44.4 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 | e89bf352984243768d716b160ef5868052020fecad94818289f0ebe740cd3f30 |
|
MD5 | 4f935169e153a78ff624a740fbec06bf |
|
BLAKE2b-256 | 6266e0ab26a6f2b6e3e70a0e8dd6ad269fa51f447a05ca6609ba72231ff8f49e |