Colour

From HaskellWiki
Revision as of 03:53, 10 July 2009 by Roconnor (talk | contribs) (Creating a short colour tutorial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This page provides a short introduction to using the colour package on hackage.

The Colour data type

The Colour a data type and its basic operations are found in the Data.Colour module. The type variable a is used to specify the numeric type used for the internal representation of the data. Typically one will use:

Colour Double

You may wish to make a type synonym for this type in your program if you will use it everywhere.

You can always use the colourConvert to change to a different internal representation type.

Creating colours

A collections of colours given by name can be found in the Data.Colour.Names module. There is also a readColourName to convert a string with one of these names into a colour. Be aware that the colour tan will conflict with the Prelude function unless you hide the Prelude function or import the module qualified.

Another way to make a colour is by specifying an RGB triple. These functions can be found in the Data.Colour.SRGB library. For example, if you have three Word8s named red, green, and blue, then

sRGB24 red green blue

will create the colour with those sRGB colour coordinates.

If you have three Doubles named red, green, and blue, then

sRGB red green blue

will produce the colour with those colour coordinates. These Double should be in the range [0,1] otherwise the resulting colour would be out of gamut (a colour gamut is a collection of representable colours on a device, such as your monitor).

Lastly, sRGB24read and sRGB24reads can create colour from string specifications of the form "#00aaff" or "00aaff".