Choose a palette
get_palette(name) returns one of five families. Pick by what you are
coloring, then pass that family’s arguments.
You are coloring |
Use |
Call |
|---|---|---|
A gradient, a hue sweep, a gauge |
the wheel |
|
Widgets, status colors, themes |
Material Design |
|
A small fixed set for dithering or a picker |
the cube |
|
Named colors such as |
the Windows 16 |
|
Text from a terminal, by ANSI color number |
ANSI |
|
An unknown name returns the Windows 16, so check the spelling when a palette has sixteen colors and you expected more.
Index it
Every palette is an indexable sequence. An index wraps, so wheel[-1] and
wheel[len(wheel)] are legal and a moving offset needs no modulo of your own.
from palettes import get_palette
wheel = get_palette("wheel", color_depth=16, length=256)
print(len(wheel), hex(wheel[0]), hex(wheel[256]), hex(wheel[-256]))
It prints 256 0xf800 0xf800 0xf800.
Use names
The Windows 16 and the Material palette add each color as an attribute, and
color_name(index) goes the other way:
md = get_palette("material_design", color_depth=16)
header = md.BLUE_S500 # the same as md.BLUE
tint = md.BLUE_S50
accent = md.BLUE_A400
win16 = get_palette("default", color_depth=16)
print(win16.RED, win16.color_name(12))
The wheel carries the Windows 16 names as attributes too, and a cube carries
the names of its own colors (BLACK, RED, WHITE and so on for size=2).
color_name returns a "#RRGGBB" string for a color with no name in the
palette’s table.
Try one in the browser
Change name to "cube", "default" or "material_design" and press
Run. It runs on MicroPython compiled to WebAssembly.
Palette families lists every argument and name.