Marangi is a lightweight utility library for working with colors.
- Normalized representation: all channels (
r,g,b,a) are floats in[0, 1] - Dual API surface
- Instance methods for in-place mutation
- Static methods for non-mutating operations
- Value semantics: explicit
copy/clone, no implicit duplication - Iterable: colors can be destructured or iterated as
[r, g, b, a]
Colorstoresr,g,b,ain linear RGBA color space- Direct construction and mutation via
set - Explicit duplication via
copyandclone
add: component-wise additionlighten/darken: scalar adjustmentslerp: linear interpolation between colorsrandom: randomized color generation
- Non-mutating equivalents for common operations
- Suitable for functional-style pipelines
Predefined color constants:
blackwhiteredgreenblueyellowpurplecyan
import { Color } from 'marangi';
const a = new Color(1, 0, 0, 1); // red
const b = new Color(0, 0, 1, 1); // blue
// interpolate (mutates a)
a.lerp(b, 0.5);
// clone
const c = a.clone();
// iterate
for (const channel of c) {
console.log(channel);
}TODO
- All operations assume normalized input; values are not implicitly clamped.
- Prefer static methods when immutability is required.