interpolateInto
Allocation-free interpolate(): writes the result into out and returns it. Same semantics and bit-identical results as interpolate(), including the option-less OKLCH default. out may be the same object as either input.
import { interpolateInto } from '@pbroom/color-kit';index.ts:89function interpolateInto(
out: Color,
color1: Color,
color2: Color,
t: number,
options?: InterpolationOptions,
): Color;Parameters
- t
number - Interpolation position; values outside
[0, 1]extrapolate - options?
InterpolationOptions - Interpolation space, hue method, and alpha handling (see
interpolate())
Returns
Example
import { interpolateInto, parse, toRgbInto } from '@pbroom/color-kit';
const a = parse('#3b82f6');
const b = parse('#ef4444');
const color = { l: 0, c: 0, h: 0, alpha: 1 };
const rgb = { r: 0, g: 0, b: 0, alpha: 1 };
for (let x = 0; x < 256; x++) {
toRgbInto(rgb, interpolateInto(color, a, b, x / 255));
// write rgb.r / rgb.g / rgb.b into an ImageData row
}