Open aarthificial opened 1 year ago
@aarthificial Did you try oklch? According to https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl#oklch-vs-hsl it's better than HCL it performs better in blue colors but maybe it coincidently it of help.
@bkahlert Thanks for the suggestion! We use chroma.js to handle colors in Motion Canvas and this problem was reported by one of our users. I told them to use a different color space but it would be great to have it fixed here.
Description When using the hcl/lch color space for interpolating between saturated colors and black, the resulting value is not correct:
The problem occurs only if one of the colors is pure black. Increasing the brightness even sliglty results in a correct color:
Similarly, if the other color has no saturation, the interpolation is also correct:
Possible explanation It seems that this may be caused by the interpolator used for hcl/lch: https://github.com/gka/chroma.js/blob/cd1b3c0926c7a85cbdc3b1453b3a94006de91a92/src/interpolator/_hsx.js#L44-L49 If one of the colors has a
NaN
hue andlb == 0
(pure black), the saturation is taken as-is from the other color. This means thatinterpolate('#f00', '#000', 1, 'hcl')
results inhcl(40, 104, 0)
instead ofhcl(40, 0, 0)
.Version
2.4.2