-- | Colour related functions module Data.CG.Minus.Colour where import Data.Colour {- colour -} import Data.Colour.SRGB import Data.Colour.Names as N -- | Opaque colour. type C = Colour Double -- | Colour with /alpha/ channel. type Ca = AlphaColour Double -- | Grey 'Colour'. mk_grey :: (Ord a,Floating a) => a -> Colour a mk_grey x = sRGB x x x -- | Reduce 'Colour' to grey. Constants are @0.3@, @0.59@ and @0.11@. to_greyscale :: (Ord a,Floating a) => Colour a -> a to_greyscale c = let (RGB r g b) = toSRGB c in r * 0.3 + g * 0.59 + b * 0.11 -- | 'mk_grey' '.' 'to_greyscale'. to_greyscale_c :: (Ord a,Floating a) => Colour a -> Colour a to_greyscale_c = mk_grey . to_greyscale -- | Discard /alpha/ channel, if possible. pureColour :: (Ord a, Fractional a) => AlphaColour a -> Colour a pureColour c = let a = alphaChannel c in if a > 0 then darken (recip a) (c `over` black) else error "transparent has no pure colour" -- * Tuples -- | Tuple to 'C', inverse of 'unC'. toC :: (Double,Double,Double) -> C toC (r,g,b) = sRGB r g b -- | 'C' to /(red,green,blue)/ tuple. unC :: C -> (Double,Double,Double) unC x = let x' = toSRGB x in (channelRed x', channelGreen x', channelBlue x') -- | Tuple to 'Ca', inverse of 'unCa'. toCa :: (Double,Double,Double,Double) -> Ca toCa (r,g,b,a) = toC (r,g,b) `withOpacity` a -- | 'Ca' to /(red,green,blue,alpha)/ tuple unCa :: Ca -> (Double,Double,Double,Double) unCa x = let x' = toSRGB (pureColour x) in (channelRed x', channelGreen x', channelBlue x', alphaChannel x) -- * Constants -- | Venetian red (@#c80815@). venetianRed :: C venetianRed = sRGB24read "#c80815" -- | Swedish azure blue (@#005b99@). swedishAzureBlue :: C swedishAzureBlue = sRGB24read "#005b99" -- | Safety orange (@#ff6600@). safetyOrange :: C safetyOrange = sRGB24read "#ff6600" -- | Dye magenta (@#ca1f7b@). dyeMagenta :: C dyeMagenta = sRGB24read "#ca1f7b" -- | Candlelight yellow (@#fcd116@). candlelightYellow :: C candlelightYellow = sRGB24read "#fcd116" -- | Subtractive primary cyan (@#00B7EB@). subtractivePrimaryCyan :: C subtractivePrimaryCyan = sRGB24read "#00B7EB" -- | Fern green (@#009246@). fernGreen :: C fernGreen = sRGB24read "#009246" -- | Sepia brown (@#704214@). sepiaBrown :: C sepiaBrown = sRGB24read "#704214" -- | The set of named colours defined in this module. non_svg_colour_set :: [C] non_svg_colour_set = [venetianRed ,swedishAzureBlue ,safetyOrange ,dyeMagenta ,candlelightYellow ,subtractivePrimaryCyan ,fernGreen ,sepiaBrown] -- * SVG colours -- | The set of named colours in the @SVG@ specification (in -- alphabetical order). svg_colour_set :: [C] svg_colour_set = [aliceblue ,antiquewhite ,aqua ,aquamarine ,azure ,beige ,bisque ,black ,blanchedalmond ,blue ,blueviolet ,brown ,burlywood ,cadetblue ,chartreuse ,chocolate ,coral ,cornflowerblue ,cornsilk ,crimson ,cyan ,darkblue ,darkcyan ,darkgoldenrod ,darkgray ,darkgreen ,darkgrey ,darkkhaki ,darkmagenta ,darkolivegreen ,darkorange ,darkorchid ,darkred ,darksalmon ,darkseagreen ,darkslateblue ,darkslategray ,darkslategrey ,darkturquoise ,darkviolet ,deeppink ,deepskyblue ,dimgray ,dimgrey ,dodgerblue ,firebrick ,floralwhite ,forestgreen ,fuchsia ,gainsboro ,ghostwhite ,gold ,goldenrod ,gray ,grey ,green ,greenyellow ,honeydew ,hotpink ,indianred ,indigo ,ivory ,khaki ,lavender ,lavenderblush ,lawngreen ,lemonchiffon ,lightblue ,lightcoral ,lightcyan ,lightgoldenrodyellow ,lightgray ,lightgreen ,lightgrey ,lightpink ,lightsalmon ,lightseagreen ,lightskyblue ,lightslategray ,lightslategrey ,lightsteelblue ,lightyellow ,lime ,limegreen ,linen ,magenta ,maroon ,mediumaquamarine ,mediumblue ,mediumorchid ,mediumpurple ,mediumseagreen ,mediumslateblue ,mediumspringgreen ,mediumturquoise ,mediumvioletred ,midnightblue ,mintcream ,mistyrose ,moccasin ,navajowhite ,navy ,oldlace ,olive ,olivedrab ,orange ,orangered ,orchid ,palegoldenrod ,palegreen ,paleturquoise ,palevioletred ,papayawhip ,peachpuff ,peru ,pink ,plum ,powderblue ,purple ,red ,rosybrown ,royalblue ,saddlebrown ,salmon ,sandybrown ,seagreen ,seashell ,sienna ,silver ,skyblue ,slateblue ,slategray ,slategrey ,snow ,springgreen ,steelblue ,N.tan ,teal ,thistle ,tomato ,turquoise ,violet ,wheat ,white ,whitesmoke ,yellow ,yellowgreen]