affection/src/Affection/Types.hs

30 lines
539 B
Haskell
Raw Normal View History

2016-03-25 15:58:46 +00:00
module Affection.Types
2016-03-26 02:50:39 +00:00
( RGBA
, newRGBA
, getR
, getG
, getB
, getA
2016-03-25 15:58:46 +00:00
) where
2016-03-26 02:50:39 +00:00
data RGBA = RGBA Int Int Int Int
2016-03-25 15:58:46 +00:00
newRGBA :: Int -> Int -> Int -> Int -> RGBA
newRGBA r g b a = RGBA (overflow r) (overflow g) (overflow b) (overflow a)
where
overflow x
2016-03-26 07:49:24 +00:00
| x < 0 = x - (x `div` 256) * 255 + 1
| otherwise = x - (x `div` 256) * 255
2016-03-26 02:50:39 +00:00
getR :: RGBA -> Int
getR (RGBA r _ _ _) = r
getG :: RGBA -> Int
getG (RGBA _ g _ _) = g
getB :: RGBA -> Int
getB (RGBA _ _ b _) = b
getA :: RGBA -> Int
getA (RGBA _ _ _ a) = a