module Graphics.Gloss.Data.Color
(
Color
, makeColor
, makeColorI
, rgbaOfColor
, mixColors
, addColors
, dim, bright
, light, dark
, withRed
, withGreen
, withBlue
, withAlpha
, greyN, black, white
, red, green, blue
, yellow, cyan, magenta
, rose, violet, azure, aquamarine, chartreuse, orange
)
where
import Graphics.Gloss.Rendering
mixColors
:: Float
-> Float
-> Color
-> Color
-> Color
mixColors m1 m2 c1 c2
= let (r1, g1, b1, a1) = rgbaOfColor c1
(r2, g2, b2, a2) = rgbaOfColor c2
m12 = m1 + m2
m1' = m1 / m12
m2' = m2 / m12
r1s = r1 * r1; r2s = r2 * r2
g1s = g1 * g1; g2s = g2 * g2
b1s = b1 * b1; b2s = b2 * b2
in makeColor
(sqrt (m1' * r1s + m2' * r2s))
(sqrt (m1' * g1s + m2' * g2s))
(sqrt (m1' * b1s + m2' * b2s))
((m1 * a1 + m2 * a2) / m12)
addColors :: Color -> Color -> Color
addColors c1 c2
= let (r1, g1, b1, a1) = rgbaOfColor c1
(r2, g2, b2, a2) = rgbaOfColor c2
in normalizeColor
(r1 + r2)
(g1 + g2)
(b1 + b2)
((a1 + a2) / 2)
dim :: Color -> Color
dim c
= let (r, g, b, a) = rgbaOfColor c
in makeColor (r / 1.2) (g / 1.2) (b / 1.2) a
bright :: Color -> Color
bright c
= let (r, g, b, a) = rgbaOfColor c
in makeColor (r * 1.2) (g * 1.2) (b * 1.2) a
light :: Color -> Color
light c
= let (r, g, b, a) = rgbaOfColor c
in makeColor (r + 0.2) (g + 0.2) (b + 0.2) a
dark :: Color -> Color
dark c
= let (r, g, b, a) = rgbaOfColor c
in makeColor (r 0.2) (g 0.2) (b 0.2) a
withRed :: Float -> Color -> Color
withRed r c
= let (_, g, b, a) = rgbaOfColor c
in makeColor r g b a
withGreen :: Float -> Color -> Color
withGreen g c
= let (r, _, b, a) = rgbaOfColor c
in makeColor r g b a
withBlue :: Float -> Color -> Color
withBlue b c
= let (r, g, _, a) = rgbaOfColor c
in makeColor r g b a
withAlpha :: Float -> Color -> Color
withAlpha a c
= let (r, g, b, _) = rgbaOfColor c
in makeColor r g b a
greyN :: Float -> Color
greyN n = makeRawColor n n n 1.0
black, white :: Color
black = makeRawColor 0.0 0.0 0.0 1.0
white = makeRawColor 1.0 1.0 1.0 1.0
red, green, blue :: Color
red = makeRawColor 1.0 0.0 0.0 1.0
green = makeRawColor 0.0 1.0 0.0 1.0
blue = makeRawColor 0.0 0.0 1.0 1.0
yellow, cyan, magenta :: Color
yellow = addColors red green
cyan = addColors green blue
magenta = addColors red blue
rose, violet, azure, aquamarine, chartreuse, orange :: Color
rose = addColors red magenta
violet = addColors magenta blue
azure = addColors blue cyan
aquamarine = addColors cyan green
chartreuse = addColors green yellow
orange = addColors yellow red
normalizeColor :: Float -> Float -> Float -> Float -> Color
normalizeColor r g b a
= let m = maximum [r, g, b]
in makeColor (r / m) (g / m) (b / m) a