Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorret HCL interpolation between saturated colors and black #310

Open
aarthificial opened this issue Feb 26, 2023 · 2 comments
Open

Incorret HCL interpolation between saturated colors and black #310

aarthificial opened this issue Feb 26, 2023 · 2 comments
Labels

Comments

@aarthificial
Copy link

aarthificial commented Feb 26, 2023

Description
When using the hcl/lch color space for interpolating between saturated colors and black, the resulting value is not correct:

interpolate('#f00', '#000', 1, 'hcl').hex() // #5b0000 (should be #000000)

The problem occurs only if one of the colors is pure black. Increasing the brightness even sliglty results in a correct color:

interpolate('#f00', '#010101', 1, 'hcl').hex() // #010101

Similarly, if the other color has no saturation, the interpolation is also correct:

interpolate('#ccc', '#000', 1, 'hcl').hex() // #000000

Possible explanation
It seems that this may be caused by the interpolator used for hcl/lch:

} else if (!isNaN(hue0)) {
hue = hue0;
if ((lbv1 == 1 || lbv1 == 0) && m != 'hsv') sat = sat0;
} else if (!isNaN(hue1)) {
hue = hue1;
if ((lbv0 == 1 || lbv0 == 0) && m != 'hsv') sat = sat1;

If one of the colors has a NaN hue and lb == 0 (pure black), the saturation is taken as-is from the other color.
This means that interpolate('#f00', '#000', 1, 'hcl') results in hcl(40, 104, 0) instead of hcl(40, 0, 0).

Version
2.4.2

@bkahlert
Copy link

bkahlert commented May 1, 2023

@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.

@aarthificial
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants