gka / chroma.js

JavaScript library for all kinds of color manipulations
https://vis4.net/chromajs/
Other
9.94k stars 543 forks source link

Question: Luminance function desaturates colors. Is it by design? #334

Open Siddhantmd opened 1 month ago

Siddhantmd commented 1 month ago

I was working on generating color scales with specific luminance values, during which I found that the luminance function desaturates colors.

For example, I have the following luminance values that I want in my color scale:

0: 0.006999999999999999 1: 0.028705077559631413 2: 0.06734518665406404 3: 0.124316794617859 4: 0.2006822101430693 5: 0.29731013608158574 6: 0.41494094204116627 7: 0.5542229103185277 8: 0.7157346487207483 9: 0.9000000000000001

In the image below, I created colors based on the original color and the above list of luminance values in two ways:

  1. Using chroma.luminance()
  2. Manipulating the 'lightness' value for the color in the HSL color space such that the resulting color matched the desired luminance. (Just to be clear, I know that lightness value of HSL color space is different from relative luminance.)

image

Both scales have the same luminance values. But as you can see, the colors generated using chroma.luminance() are desaturated. Is that by design? If so, why?