scale
scale builds a color scale between two endpoints. Use it for a stepped gradient or ordered data. The default OKLab interpolation gives you stops spaced evenly along the path in that space.
Example
import { colore } from 'colore-js';
import { scale } from 'colore-js/fn';
colore('#ef4444').scale('#3b82f6', { steps: 3 }).map((color) => color.css());
scale('#ef4444', '#3b82f6', { steps: 3 });
// ['#ef4444', '#a775a5', '#3b82f6'] from either line
Syntax
colore(from).scale(to: ColorInput | Color, options?: ScaleOptions): Color[]
scale(from: ColorInput, to: ColorInput, options?: ScaleOptions): string[]
Parameters
Returns
The method returns Color[]. The function returns CSS strings, including Display P3 or OKLCH when a color falls outside sRGB.
Throws
A ColorError for an invalid color, unsupported space, unknown option, or step count under two or with a fractional part.
Create seven stops for an ordered chart
import { scale } from 'colore-js/fn';
scale('#ef4444', '#3b82f6', { steps: 7 });
// ['#ef4444', '#d85c69', '#c16b88', '#a775a5', '#8b7cc0', '#6a80db', '#3b82f6']
#ef4444
#d85c69
#c16b88
#a775a5
#8b7cc0
#6a80db
#3b82f6
Related
- interpolate to sample at one position
- palette for shades from one base
- Chart colors for distinct series in unordered charts