palettes

August 23, 2026 ยท View on GitHub

๐ŸŽจ palettes

A lightweight, pure-Python color palette and UI theme engine for microcontrollers, embedded displays, desktop Python, and the browser.

๐Ÿ“ฆ MIP: palettes ๐Ÿ PyPI: pydevices-palettes โšก Zero C Dependencies ๐ŸŒ MicroPython ยท CircuitPython ยท CPython ยท Direct WebAssembly ยท Pyodide

๐ŸŒˆ Color Wheels

Generate continuous color ramps and rainbow gradients with configurable saturation and hue lengths.

๐ŸŽฏ Material Design

Access standardized semantic UI palettes with shades from 50 to 900 for modern themes and widgets.

๐ŸงŠ Color Cubes

Evenly distributed 8, 27, 64, and 125 color spaces optimized for dithering and quantized graphics.

๐Ÿ”„ Byte-Swapping

First-class 16-bit RGB565 byte swapping (swapped=True) for direct SPI panel compatibility.


๐Ÿš€ Quick Install

=== "MicroPython (MIP)"

```python
import mip
mip.install("palettes", index="https://PyDevices.github.io/mip")
```

=== "CPython (TestPyPI)"

```bash
pip install -i https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ pydevices-palettes
```

=== "CircuitPython"

Copy the `palettes/` folder from the repository into your board's `CIRCUITPY/lib/` folder.

=== "PyScript / Pyodide"

In PyScript headers or Pyodide configurations, declare:
```python
import micropip
await micropip.install(
    "pydevices-palettes", index_urls="https://test.pypi.org/simple/"
)

from palettes import get_palette
```

The wheel is named `pydevices-palettes`; the module you import is
`palettes`. On MicroPython the MIP package name is `palettes`
(`mip.install("palettes", index="https://PyDevices.github.io/mip")`).

๐Ÿ’ป Live Interactive Demo

Try tweaking the palette parameters below. Click โ–ถ Run to execute the code with direct MicroPython WebAssembly:

display = AutoDisplay(width=320, height=240, canvas_id=CANVAS_ID) display.fill(0x1082)

Generate a 256-color wheel palette

palette = get_palette("wheel", color_depth=16, length=256, saturation=1.0)

Draw vertical color bars

bar_width = display.width // 32 for i in range(32): color = palette[i * 8] display.fill_rect(i * bar_width, 20, bar_width, 100, color)

Material Design amber ramp

md = get_palette("material_design", color_depth=16) shades = [ md.AMBER_S50, md.AMBER_S100, md.AMBER_S200, md.AMBER_S300, md.AMBER_S400, md.AMBER_S500, md.AMBER_S600, md.AMBER_S700, md.AMBER_S800, md.AMBER_S900 ] for i, color in enumerate(shades): display.fill_rect(i * 30 + 10, 140, 26, 60, color)

display.show() print("Drawn 32 color wheel bands and 10 Material Design amber shades!")

Initializing Pythonโ€ฆ


๐Ÿ“– Practical Usage Pattern

Construct a palette once and index it inside your application draw loop:

from palettes import get_palette

# Match the display's native color depth (16-bit RGB565)
palette = get_palette(name="wheel", color_depth=16, length=256, saturation=1.0)

# Index directly into the palette
for i in range(16):
    display_drv.fill_rect(0, i * 8, 80, 8, palette[i * 16])

If the physical display expects byte-swapped 16-bit values (common on SPI TFTs like the ST7789 or ILI9341), pass swapped=True:

palette = get_palette(name="wheel", color_depth=16, swapped=True)

Explore full-color gradient and animation applications built with palettes:

๐ŸŽจ Palettes Gallery Showcase

Interactive color visualizer exploring Material Design tokens, HSV wheels, and RGB cubes.

โ–ถ Launch Live Demo

๐Ÿชถ Rainbow Feathers

Geometric generative art rendering smooth multi-chromatic feather curves.

โ–ถ Launch Live Demo

๐Ÿ”„ Palette Rotations

Real-time palette cycling and rotational sweeps demonstrating zero-cost animations.

โ–ถ Launch Live Demo

๐Ÿ“œ Gradient Scrolling

Hardware vertical scrolling demonstration paired with high-precision palette shading.

โ–ถ Launch Live Demo


๐Ÿ“š Documentation Map

  • ๐ŸŽจ Palette Gallery โ€” Visual previews and tables for Wheel, Material Design, Cube, and Win16 palettes.
  • ๐Ÿ”ข Color Math & Formats โ€” RGB565 bit-packing, endianness swapping, and HSL/HSV math.
  • ๐Ÿงฉ Integrations โ€” Recipes for pygraphics, pdwidgets, and hardware display drivers.
  • ๐Ÿ“š API Reference โ€” Complete docstrings and class references.