For a given palette, return color by any float index. Useful for interpolating colormaps, color palettes or gradients.
Usage
const interpolate = ; let colormap = ;let black = ; // 'rgb(0, 0, 0)'let white = ; // 'rgb(255, 255, 255)'let gray = ; // 'rgb(128, 128, 128)'
API
let palette = require('color-interpolate')(colors)
Create interpolator from a list of colors
. Colors can be in any format: CSS color string, array with RGB channel values, object with r
, g
, b
or h
, s
, l
channel values or even a number, see color-parse for reference.
let color = palette(index, fn?)
Get interpolated color from palette by index
value within 0..1
range. Pass optional fn
interpolation function, by default lerp is used, but smoothstep can be used as an alternative.
Example:
const palettes = const palette = palettes32 let activeColor = // 'rgb(51, 23 47)'let background = // 'rgb(255, 255, 255)'let foreground = // 'rgb(0, 0, 0)'
Credits
Thanks to @mattdesl for interpolation functions and @mikkoh for API insight in interpolation-arrays.
Related
colormap — collection of beautiful colormaps, a good source for palettes.
nice-color-palettes — collection of beautiful color palettes from colourlovers.
color-alpha — change alpha of a color string.
color-spectrum — convert spectrum, like FFT result, to color.
color-space — collection of color space transforms, useful for custom interpolation modes.
© Dmitry Yv. MIT License