mixInto
Allocation-free mix(): writes the mix of color1 and color2 into out and returns it. Same semantics and bit-identical results as mix(), including the option-less OKLCH path. out may be the same object as either input, so mixInto(a, a, b, t) blends b into a in place.
import { mixInto } from '@pbroom/color-kit';index.ts:243function mixInto(
out: Color,
color1: Color,
color2: Color,
t?: number,
options?: InterpolationOptions,
): Color;Parameters
- t?
numberdefault0.5 - Mix position (default
0.5) - options?
InterpolationOptions - Interpolation space, hue method, and alpha handling (see
mix())
Returns
Example
import { mixInto, parse } from '@pbroom/color-kit';
const red = parse('#ff0000');
const lime = parse('#00ff00');
const out = { l: 0, c: 0, h: 0, alpha: 1 };
for (let i = 0; i <= 100; i++) {
mixInto(out, red, lime, i / 100, { space: 'linear-srgb' });
// ...use out without allocating per step
}