aboutsummaryrefslogtreecommitdiff
path: root/src/Utils/Color.elm
blob: f9e344fdf41a49c8d017da9eaff5579817ac72a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Utils.Color exposing
  ( merge
  , spin
  )

import Color as Color exposing (Color)

merge : Float -> Color -> Color -> Color
merge ratio c1 c2 =
  let rgb1 = Color.toRgb c1
      rgb2 = Color.toRgb c2
      mergePartFloat x y = ratio * x + (1 - ratio) * y
      mergePartInt x y = truncate <| ratio * (toFloat x) + (1 - ratio) * (toFloat y)
  in  Color.rgba
        (mergePartInt rgb1.red rgb2.red)
        (mergePartInt rgb1.green rgb2.green)
        (mergePartInt rgb1.blue rgb2.blue)
        (mergePartFloat rgb1.alpha rgb2.alpha)

spin : Float -> Color -> Color
spin d color =
  let { hue, saturation, lightness, alpha } = Color.toHsl color
  in  Color.hsla (hue + degrees d) saturation lightness alpha