Skip to main content

Palette

A fixed length color palette.

Palette are used with displays to keep the storage needed for images low. They can also be used with LEDs to create multi-color gradients.

at, setAt

These function allow to lookup and update the color of palette at indices.

import { Palette } from "@devicescript/graphics"

const palette = Palette.arcade()

// lookup color
const c = palette.at(2)

// update color
palette.setAt(2, 0x00_00_ff)

interpolateColor

Interpolates a [0, 1] value into a color of the palette, regardless of the palette size.

import { Palette } from "@devicescript/graphics"
import { interpolateColor } from "@devicescript/runtime"

const palette = Palette.arcade()

const c = interpolateColor(palette, 0.5)

correctGamma

For palette used with LEDs, you can preapply gamma correction.

import { Palette } from "@devicescript/graphics"
import { correctGamma } from "@devicescript/runtime"

const palette = Palette.arcade()
correctGamma(palette)