-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.hs
40 lines (34 loc) · 1.05 KB
/
Color.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE TypeSynonymInstances, MultiParamTypeClasses #-}
module Color where
import Math
import Control.Parallel.Strategies hiding (dot)
import Control.DeepSeq
-- | Lazy RGB triplet, components in the range [0..1].
data Color = Color {
cRed :: Flt,
cGreen :: Flt,
cBlue :: Flt
}
instance (NumTuple Flt) Color where
tupleToList (Color r g b) = [r, g, b]
tupleFromList [r, g, b] = Color r g b
tupleFromList _ = error "Invalid number of elements in list for this color!"
instance Show Color where
show = showTuple
instance Mult Color Color Flt where
(.*.) = dot
instance Mult Color Flt Color where (.*.) = (.*)
instance Mult Flt Color Color where (.*.) = (*.)
instance Div Color Flt
instance Add Color where (.+.) = addt
instance Sub Color where (.-.) = subt
instance NFData Color where rnf = rnfTuple
black = Color 0 0 0
white = Color 1 1 1
red = Color 1 0 0
green = Color 0 1 0
blue = Color 0 0 1
cyan = Color 0 1 1
yellow = Color 1 1 0
magenta = Color 1 0 1
-- vim: expandtab smarttab sw=4 ts=4