Zero-dependency color library for the Optic engine.
This crate provides color types, conversions, channel arithmetic, and a gradient evaluator. It has no external dependencies and can be used independently of the rest of the engine.
Types
| Type | Components | Channels | Arithmetic |
|---|---|---|---|
[RGBA] |
red, green, blue, alpha | [ChannelArray<4>] |
Add, Sub, Mul, Div |
[RGB] |
red, green, blue | [ChannelArray<3>] |
Add, Sub, Mul, Div |
[HSV] |
hue, saturation, value | — | — |
[HSL] |
hue, saturation, lightness | — | — |
HSV and HSL deliberately avoid arithmetic because hue wraparound
makes componentwise operations produce wrong colors. Convert to [RGBA]
first (via .into() or [ToRgba]), then operate, then convert back.
Conversions
Every color type implements [ToRgba] and [FromRgba], so you can use
generics that accept "any color-like type":
use *;
Direct From impls exist for all pairs:
From<RGB/HSV/HSL> for RGBAFrom<RGBA> for RGB/HSV/HSL
Gradients
[Gradient] supports multiple interpolation modes, color spaces,
and wrap modes:
use *;
let grad = two_color
.set_color_space;
let mid = grad.sample; // RGBA
Named colors
The crate exports ~90 named [RGBA] constants (see [optic_color::constants]).
Examples: [RED], [MIDNIGHT], [GOLD], [LAVENDER], [OBSIDIAN].