gloss 1.9.3.1 → 1.9.4.1
raw patch · 2 files changed
+68/−25 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Graphics.Gloss.Data.Color: withAlpha :: Float -> Color -> Color
+ Graphics.Gloss.Data.Color: withBlue :: Float -> Color -> Color
+ Graphics.Gloss.Data.Color: withGreen :: Float -> Color -> Color
+ Graphics.Gloss.Data.Color: withRed :: Float -> Color -> Color
Files
- Graphics/Gloss/Data/Color.hs +67/−24
- gloss.cabal +1/−1
Graphics/Gloss/Data/Color.hs view
@@ -13,6 +13,11 @@ , dim, bright , light, dark + , withRed+ , withGreen+ , withBlue+ , withAlpha+ -- ** Pre-defined colors , greyN, black, white @@ -29,48 +34,47 @@ import Graphics.Gloss.Rendering --- | Normalise a color to the value of its largest RGB component.-normalizeColor :: Color -> Color-normalizeColor cc- = let (r, g, b, a) = rgbaOfColor cc- m = maximum [r, g, b]- in makeColor (r / m) (g / m) (b / m) a - -- Color functions ------------------------------------------------------------- -- | Mix two colors with the given ratios. mixColors - :: Float -- ^ Ratio of first color.- -> Float -- ^ Ratio of second color.+ :: Float -- ^ Proportion of first color.+ -> Float -- ^ Proportion of second color. -> Color -- ^ First color. -> Color -- ^ Second color. -> Color -- ^ Resulting color. -mixColors ratio1 ratio2 c1 c2+mixColors m1 m2 c1 c2 = let (r1, g1, b1, a1) = rgbaOfColor c1 (r2, g2, b2, a2) = rgbaOfColor c2 - total = ratio1 + ratio2- m1 = ratio1 / total- m2 = ratio2 / total+ -- Normalise mixing proportions to ratios.+ m12 = m1 + m2+ m1' = m1 / m12+ m2' = m2 / m12 - in makeColor - (m1 * r1 + m2 * r2)- (m1 * g1 + m2 * g2)- (m1 * b1 + m2 * b2)- (m1 * a1 + m2 * a2)+ -- Colors components should be added via sum of squares,+ -- otherwise the result will be too dark.+ 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) --- | Add RGB components of a color component-wise, then normalise--- them to the highest resulting one. The alpha components are averaged.++-- | Add RGB components of a color component-wise,+-- then normalise them to the highest resulting one. +-- The alpha components are averaged. addColors :: Color -> Color -> Color addColors c1 c2 = let (r1, g1, b1, a1) = rgbaOfColor c1 (r2, g2, b2, a2) = rgbaOfColor c2 in normalizeColor - $ makeColor (r1 + r2) (g1 + g2) (b1 + b2)@@ -105,10 +109,40 @@ in makeColor (r - 0.2) (g - 0.2) (b - 0.2) a +-------------------------------------------------------------------------------+-- | Set the alpha value of a `Color`.+withRed :: Float -> Color -> Color+withRed r c+ = let (_, g, b, a) = rgbaOfColor c+ in makeColor r g b a+++-- | Set the alpha value of a `Color`.+withGreen :: Float -> Color -> Color+withGreen g c+ = let (r, _, b, a) = rgbaOfColor c+ in makeColor r g b a+++-- | Set the alpha value of a `Color`.+withBlue :: Float -> Color -> Color+withBlue b c+ = let (r, g, _, a) = rgbaOfColor c+ in makeColor r g b a+++-- | Set the alpha value of a `Color`.+withAlpha :: Float -> Color -> Color+withAlpha a c+ = let (r, g, b, _) = rgbaOfColor c+ in makeColor r g b a++ -- Pre-defined Colors --------------------------------------------------------- -- | A greyness of a given order.-greyN :: Float -- ^ Range is 0 = black, to 1 = white.- -> Color+-- +-- Range is 0 = black, to 1 = white.+greyN :: Float -> Color greyN n = makeRawColor n n n 1.0 black, white :: Color@@ -135,3 +169,12 @@ aquamarine = addColors cyan green chartreuse = addColors green yellow orange = addColors yellow red+++-------------------------------------------------------------------------------+-- | Normalise a color to the value of its largest RGB component.+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+
gloss.cabal view
@@ -1,5 +1,5 @@ Name: gloss-Version: 1.9.3.1+Version: 1.9.4.1 License: MIT License-file: LICENSE Author: Ben Lippmeier