Open lazd opened 5 years ago
this is due to the fact that internally, chroma.js is rounding the RGB values after it converted them from hsl. this is fine if you're planning on using the color as RGB but we're losing precision if the plan is to go back to hsl. I need to check back with older versions of chroma, but I think it's always been like that. https://github.com/gka/chroma.js/blob/master/src/io/hsl/hsl2rgb.js#L31
chroma({ h: 20, s: 1, v: 0 })
is pure black #000000
, and while you could argue for both, chromajs decided that black is, like white and gray, a hue-less color, hence the saturation is 0.
@gka thanks for the reply. I understand the reason for the s: 1, v:0
transformation.
I tested 1.4.x of Chroma and found the same issues, but I did not test older versions.
What are you thinking should be done to address this, if anything?
As for my use case: Right now I am using Chroma to read in colors provided by the user, but I'm also using it after the fact to modify the colors based on picked S/V values. You can see my prototype here: https://codepen.io/lazd/pen/jQdGVq?editors=0010
s
can affect l
, for example chroma({ h: 0, s: 0.106, l: 0.16 }).set('hsl.s', 0.9).get('hsl.l') => 0.1588235294117647
).Now part of this is because of how I implemented things (manipulating HSV, but displaying as HSL), but part of it is because of Chroma's not preserving the H/S/V that I am manipulating. I'd appreciate any suggestions you have as to how to handle this, as I'm rather green (pun intended) when it comes to manipulating color across spaces.
I see. the only way for this to be fixed in chroma.js would be to store RGB channels as floats instead of rounding to bytes, which essentially means storing more precision than true color (24bit).
I think what I would do is to store the active HSL coordinate somewhere outside of chroma.js.
Run the following in the console on the docs page at https://gka.github.io/chroma.js/
Hue changes when S and V change
Expected: In all of the above cases,
h
should be3
.S/V change when bounds are reached
Expected:
s
should be1
.Environment
Chroma 2.0.2 Chrome Version 71.0.3578.98 (Official Build) (64-bit) on macOS 10.12.6