colors

colors

Color and theming library for Zirric.

colors provides an HSL color model, conversions between hex, RGB and HSL, the usual manipulation primitives (tint, shade, tone, mix, complement) and a set of color schemes that generate an endless series of colors from one or more base colors.

Installation

Declare colors as a dependency of your module:

mod ui

import cave

@cave.Dependencies()
data UI {
    @cave.Git("https://code.knabel.dev/zirric-lang/colors")
    @cave.Version("main")
    colors
}

Usage

import colors { Color, rgb, hex, tint }
import colors.scheme { Analogous, Rainbow }

const brand = hex(0xFF3EC0)
const lighter = tint(brand, 0.2)

// A scheme returns the nth color of a series.
const palette = Analogous(brand, Degree(30))
const second = palette.color(1)

Colors are normalized on construction: hues wrap around at 360 degrees, saturation and lightness are clamped to 0.0 … 1.0.

Modules

Module Description
colors The Color type, constructors and manipulation functions, plus Theme.
colors.scheme The Scheme attribute and the built-in schemes.
colors.maths Degree and Fraction, the normalizing numeric wrappers.

Themes

A Theme bundles five schemes — accent, highlight, surface, border and text — with four fixed status colors for warning, error, info and success. The library ships retroDark as a built-in example.

Status

Early draft. hex is not implemented yet, so anything built on top of it currently panics.

License

See LICENSE.