I'm trying to convert some HSL
value to RBG
with Data.Colour module. Hackage doc said that Hue
is always in the range 0-360. But there are now any ranges of Saturation
and Lightness
values. Are they in [0,100] or in [0,1] ranges?
I suppose that first variant is right, but seems like it is not.
λ> hsl 100 50 50
RGB {channelRed = 866.6666666666692, channelGreen = -2400.0, channelBlue = 2500.0}
Than I tried to use the range [0, 1] for both saturation and lightness.
λ> fmap truncate . (\(h,s,l) -> hsl h s l) $ (0,0,0)
RGB {channelRed = 0, channelGreen = 0, channelBlue = 0}
it :: RGB Integer
That why I'm start thinking that only Saturation
should be a Double
in [0,1]
.
For example we have some color value in HSL
format.
λ> let c = (34.0,0.54,68.0)
c :: (Double, Double, Double)
Than we convert it to RGB
and truncate all values
λ> fmap truncate . (\(h,s,l) -> hsl h s l) $ c
RGB {channelRed = 31, channelGreen = 63, channelBlue = 104}
But (31,63,104)::RGB
is (214,54,26)::HSL
like some online color-converters said.
What am I doing wrong?
It looks like the package uses the range [0, 1]
for both lightness and saturation, but note that it also uses this range for RGB values, and not [0, 255]
as you seem to be assuming. Taking this into account, I get (almost) the expected values:
> fmap (truncate . (* 255)) $ hsl 214 0.54 0.26
RGB {channelRed = 30, channelGreen = 61, channelBlue = 102}