What it does
Spectral.js models paint-like mixtures from familiar colour inputs and is distributed under the MIT licence. Its JavaScript Color objects support weighted mixing, stepped palettes and gradients, with controls for pigment dominance and display gamut.
Wrap each HEX value, CSS string or RGB array in a Color object before mixing. Supply a factor for each colour; whole-number factors are normalized. A palette call generates a chosen number of steps between two colours, while gradients place several stops between zero and one.
Adjust tintingStrength when one colour dominates a mixture. That is a user judgement, not an automatically measured pigment property. The model assumes a constant scattering coefficient, so its results are an approximation of pigment behaviour.
The MIT-licensed library returns Color objects. toString produces HEX or RGB and can map or clip out-of-gamut results. The documented GLSL implementation mixes two to four colours; older examples using raw values need conversion to the current Color-object interface.
Strengths
- Weighted mixtures and multi-stop gradients share the colour model.
- Tinting strength can reduce a dominant colour’s influence.
- Output includes explicit gamut handling.
Watch out for
- The model assumes constant scattering.
- The GLSL implementation supports only two to four input colours.
Best for
- Creative applications implementing paint-like colour mixing
Sources
- Spectral.js model, Color interface and MIT licence (Oct 27, 2026)
