aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Color.elm
blob: 8452efa9ec64c296e82d38bd64f67183f59df7fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Model.Color
  ( Color
  , htmlOutput
  , mergeColors
  ) where

type alias Color =
  { red : Int
  , green : Int
  , blue : Int
  }

htmlOutput : Color -> String
htmlOutput color = "rgb(" ++ (toString color.red) ++ ", " ++ (toString color.green) ++ ", " ++ (toString color.blue) ++ ")"

mergeColors : Float -> Color -> Color -> Color
mergeColors ratio c1 c2 =
  let mergePart x y = truncate (ratio * (toFloat x) + (1 - ratio) * (toFloat y))
  in  { red = mergePart c1.red c2.red
      , green = mergePart c1.green c2.green
      , blue = mergePart c1.blue c2.blue
      }