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 :: Float -> Float -> Color -> Color -> Color
mixColors Float
m1 Float
m2 Color
c1 Color
c2
= let (Float
r1, Float
g1, Float
b1, Float
a1) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c1
(Float
r2, Float
g2, Float
b2, Float
a2) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c2
m12 :: Float
m12 = Float
m1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
m2
m1' :: Float
m1' = Float
m1 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m12
m2' :: Float
m2' = Float
m2 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m12
r1s :: Float
r1s = Float
r1 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
r1; r2s :: Float
r2s = Float
r2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
r2
g1s :: Float
g1s = Float
g1 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
g1; g2s :: Float
g2s = Float
g2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
g2
b1s :: Float
b1s = Float
b1 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
b1; b2s :: Float
b2s = Float
b2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
b2
in Float -> Float -> Float -> Float -> Color
makeColor
(Float -> Float
forall a. Floating a => a -> a
sqrt (Float
m1' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
r1s Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
m2' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
r2s))
(Float -> Float
forall a. Floating a => a -> a
sqrt (Float
m1' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
g1s Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
m2' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
g2s))
(Float -> Float
forall a. Floating a => a -> a
sqrt (Float
m1' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
b1s Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
m2' Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
b2s))
((Float
m1 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
a1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
m2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
a2) Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m12)
addColors :: Color -> Color -> Color
addColors :: Color -> Color -> Color
addColors Color
c1 Color
c2
= let (Float
r1, Float
g1, Float
b1, Float
a1) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c1
(Float
r2, Float
g2, Float
b2, Float
a2) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c2
in Float -> Float -> Float -> Float -> Color
normalizeColor
(Float
r1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
r2)
(Float
g1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
g2)
(Float
b1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
b2)
((Float
a1 Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
a2) Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
2)
dim :: Color -> Color
dim :: Color -> Color
dim Color
c
= let (Float
r, Float
g, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor (Float
r Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
1.2) (Float
g Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
1.2) (Float
b Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
1.2) Float
a
bright :: Color -> Color
bright :: Color -> Color
bright Color
c
= let (Float
r, Float
g, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor (Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
1.2) (Float
g Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
1.2) (Float
b Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
1.2) Float
a
light :: Color -> Color
light :: Color -> Color
light Color
c
= let (Float
r, Float
g, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor (Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
0.2) (Float
g Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
0.2) (Float
b Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
0.2) Float
a
dark :: Color -> Color
dark :: Color -> Color
dark Color
c
= let (Float
r, Float
g, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor (Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
0.2) (Float
g Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
0.2) (Float
b Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
0.2) Float
a
withRed :: Float -> Color -> Color
withRed :: Float -> Color -> Color
withRed Float
r Color
c
= let (Float
_, Float
g, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor Float
r Float
g Float
b Float
a
withGreen :: Float -> Color -> Color
withGreen :: Float -> Color -> Color
withGreen Float
g Color
c
= let (Float
r, Float
_, Float
b, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor Float
r Float
g Float
b Float
a
withBlue :: Float -> Color -> Color
withBlue :: Float -> Color -> Color
withBlue Float
b Color
c
= let (Float
r, Float
g, Float
_, Float
a) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor Float
r Float
g Float
b Float
a
withAlpha :: Float -> Color -> Color
withAlpha :: Float -> Color -> Color
withAlpha Float
a Color
c
= let (Float
r, Float
g, Float
b, Float
_) = Color -> (Float, Float, Float, Float)
rgbaOfColor Color
c
in Float -> Float -> Float -> Float -> Color
makeColor Float
r Float
g Float
b Float
a
greyN :: Float -> Color
greyN :: Float -> Color
greyN Float
n = Float -> Float -> Float -> Float -> Color
makeRawColor Float
n Float
n Float
n Float
1.0
black, white :: Color
black :: Color
black = Float -> Float -> Float -> Float -> Color
makeRawColor Float
0.0 Float
0.0 Float
0.0 Float
1.0
white :: Color
white = Float -> Float -> Float -> Float -> Color
makeRawColor Float
1.0 Float
1.0 Float
1.0 Float
1.0
red, green, blue :: Color
red :: Color
red = Float -> Float -> Float -> Float -> Color
makeRawColor Float
1.0 Float
0.0 Float
0.0 Float
1.0
green :: Color
green = Float -> Float -> Float -> Float -> Color
makeRawColor Float
0.0 Float
1.0 Float
0.0 Float
1.0
blue :: Color
blue = Float -> Float -> Float -> Float -> Color
makeRawColor Float
0.0 Float
0.0 Float
1.0 Float
1.0
yellow, cyan, magenta :: Color
yellow :: Color
yellow = Color -> Color -> Color
addColors Color
red Color
green
cyan :: Color
cyan = Color -> Color -> Color
addColors Color
green Color
blue
magenta :: Color
magenta = Color -> Color -> Color
addColors Color
red Color
blue
rose, violet, azure, aquamarine, chartreuse, orange :: Color
rose :: Color
rose = Color -> Color -> Color
addColors Color
red Color
magenta
violet :: Color
violet = Color -> Color -> Color
addColors Color
magenta Color
blue
azure :: Color
azure = Color -> Color -> Color
addColors Color
blue Color
cyan
aquamarine :: Color
aquamarine = Color -> Color -> Color
addColors Color
cyan Color
green
chartreuse :: Color
chartreuse = Color -> Color -> Color
addColors Color
green Color
yellow
orange :: Color
orange = Color -> Color -> Color
addColors Color
yellow Color
red
normalizeColor :: Float -> Float -> Float -> Float -> Color
normalizeColor :: Float -> Float -> Float -> Float -> Color
normalizeColor Float
r Float
g Float
b Float
a
= let m :: Float
m = [Float] -> Float
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [Float
r, Float
g, Float
b]
in Float -> Float -> Float -> Float -> Color
makeColor (Float
r Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m) (Float
g Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m) (Float
b Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
m) Float
a