module Data.Colour.RGBSpace.HSL
(RGB
,hslView
,hue, saturation, lightness
,hsl
)
where
import Data.Colour.RGB
hslView :: (Fractional a, Ord a) => RGB a -> (a,a,a)
hslView :: forall a. (Fractional a, Ord a) => RGB a -> (a, a, a)
hslView RGB a
rgb = (a
h,a
s,a
l)
where
(a
h,a
s,a
l,a
_,a
_) = RGB a -> (a, a, a, a, a)
forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
hslsv RGB a
rgb
saturation :: (Fractional a, Ord a) => RGB a -> a
saturation :: forall a. (Fractional a, Ord a) => RGB a -> a
saturation RGB a
rgb = a
s
where
(a
_,a
s,a
_,a
_,a
_) = RGB a -> (a, a, a, a, a)
forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
hslsv RGB a
rgb
lightness :: (Fractional a, Ord a) => RGB a -> a
lightness :: forall a. (Fractional a, Ord a) => RGB a -> a
lightness RGB a
rgb = a
l
where
(a
_,a
_,a
l,a
_,a
_) = RGB a -> (a, a, a, a, a)
forall a. (Fractional a, Ord a) => RGB a -> (a, a, a, a, a)
hslsv RGB a
rgb
hsl :: (RealFrac a, Ord a) => a -> a -> a -> RGB a
hsl :: forall a. (RealFrac a, Ord a) => a -> a -> a -> RGB a
hsl a
h a
s a
l = (a -> a) -> RGB a -> RGB a
forall a b. (a -> b) -> RGB a -> RGB b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
component RGB a
t
where
hk :: a
hk = a
ha -> a -> a
forall a. Fractional a => a -> a -> a
/a
360
tr :: a
tr = a -> a
forall {a}. RealFrac a => a -> a
mod1 (a
hk a -> a -> a
forall a. Num a => a -> a -> a
+ a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
3)
tg :: a
tg = a -> a
forall {a}. RealFrac a => a -> a
mod1 a
hk
tb :: a
tb = a -> a
forall {a}. RealFrac a => a -> a
mod1 (a
hk a -> a -> a
forall a. Num a => a -> a -> a
- a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
3)
t :: RGB a
t = a -> a -> a -> RGB a
forall a. a -> a -> a -> RGB a
RGB a
tr a
tg a
tb
q :: a
q | a
l a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
0.5 = a
la -> a -> a
forall a. Num a => a -> a -> a
*(a
1a -> a -> a
forall a. Num a => a -> a -> a
+a
s)
| Bool
otherwise = a
l a -> a -> a
forall a. Num a => a -> a -> a
+ a
s a -> a -> a
forall a. Num a => a -> a -> a
- a
la -> a -> a
forall a. Num a => a -> a -> a
*a
s
p :: a
p = a
2a -> a -> a
forall a. Num a => a -> a -> a
*a
l a -> a -> a
forall a. Num a => a -> a -> a
- a
q
component :: a -> a
component a
t | a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
6 = a
p a -> a -> a
forall a. Num a => a -> a -> a
+ ((a
qa -> a -> a
forall a. Num a => a -> a -> a
-a
p)a -> a -> a
forall a. Num a => a -> a -> a
*a
6a -> a -> a
forall a. Num a => a -> a -> a
*a
t)
| a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1a -> a -> a
forall a. Fractional a => a -> a -> a
/a
2 = a
q
| a
t a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
2a -> a -> a
forall a. Fractional a => a -> a -> a
/a
3 = a
p a -> a -> a
forall a. Num a => a -> a -> a
+ ((a
qa -> a -> a
forall a. Num a => a -> a -> a
-a
p)a -> a -> a
forall a. Num a => a -> a -> a
*a
6a -> a -> a
forall a. Num a => a -> a -> a
*(a
2a -> a -> a
forall a. Fractional a => a -> a -> a
/a
3a -> a -> a
forall a. Num a => a -> a -> a
-a
t))
| Bool
otherwise = a
p