AC-Colour-1.1.4: Efficient RGB colour types.



This module provides Colour, which stores linear RGB (red, green, blue) colour values where each channel is a Double. It also provides arithmetic over such colours, and a few predefined colours.



data Colour Source

The main colour type. It stores three channels (red, green and blue) as linear Double values normally ranging from 0 to 1. (0 represents minimum intensity, 1 represents maximum. Black is therefore Colour 0 0 0 and white is Colour 1 1 1.)

The channel values are stored as strict, unboxed fields, so operating on Colours should be quite efficient in time and space.

The Num and Fractional instances provide arithmetic for Colours. Note that (*) acts channel-wise; this is usually what is wanted.




red :: !Double
green :: !Double
blue :: !Double

cmap :: (Double -> Double) -> Colour -> ColourSource

Apply a function to every channel in a colour. (Mostly used internally, but exposed here in case it may be useful.)

czip :: (Double -> Double -> Double) -> Colour -> Colour -> ColourSource

This is similar to Data.List.zipWith. (Mostly used internally, but exposed here in case it may be useful.)

cfold :: (Double -> Double -> Double) -> Colour -> DoubleSource

Use a function to collapse a Colour into a Double. No particular order of application is promised.

grey :: Double -> ColourSource

Turn a Double into a shade of grey.

cscale :: Double -> Colour -> ColourSource

Scale a Colour by a specified amount. (That is, change the brightness while not affecting the shade.)

clip :: Colour -> ColourSource

Take a Colour and clip all channels to the range 0--1 inclusive. Any value outside that range will be replaced with the nearest endpoint (i.e., 0 for negative numbers, 1 for positive numbers higher than 1). Values inside the range are unaffected.

unpack :: Colour -> (Double, Double, Double)Source

Convert a Colour into a tuple.

pack :: (Double, Double, Double) -> ColourSource

Convert a tuple into a Colour.

cBlack :: ColourSource

Constant: Black.

cRed :: ColourSource

Constant: Red.

cYellow :: ColourSource

Constant: Yellow.

cGreen :: ColourSource

Constant: Green.

cCyan :: ColourSource

Constant: Cyan.

cBlue :: ColourSource

Constant: Blue.

cMagenta :: ColourSource

Constant: Magenta.

cWhite :: ColourSource

Constant: White.