Datatypes for representing the human perception of colour. Includes common operations for blending and compositing colours. The most common way of creating colours is either by name (see Data.Colour.Names) or by giving an sRGB triple (see Data.Colour.SRGB).
Methods of specifying Colours can be found in
Colours can be specified in a generic Data.Colour.RGBSpace.RGBSpace
by using
- data Colour a
- colourConvert :: (Fractional b, Real a) => Colour a -> Colour b
- data AlphaColour a
- opaque :: Num a => Colour a -> AlphaColour a
- withOpacity :: Num a => Colour a -> a -> AlphaColour a
- transparent :: Num a => AlphaColour a
- alphaColourConvert :: (Fractional b, Real a) => AlphaColour a -> AlphaColour b
- alphaChannel :: AlphaColour a -> a
- class AffineSpace f where
- affineCombo :: Num a => [(a, f a)] -> f a -> f a
- blend :: (Num a, AffineSpace f) => a -> f a -> f a -> f a
- class ColourOps f where
- over :: Num a => AlphaColour a -> f a -> f a
- darken :: Num a => a -> f a -> f a
- dissolve :: Num a => a -> AlphaColour a -> AlphaColour a
- atop :: Fractional a => AlphaColour a -> AlphaColour a -> AlphaColour a
Colour type
colourConvert :: (Fractional b, Real a) => Colour a -> Colour bSource
Change the type used to represent the colour coordinates.
data AlphaColour a Source
This type represents a Colour
that may be semi-transparent.
The Monoid
instance allows you to composite colours.
x `mappend` y == x `over` y
To get the (pre-multiplied) colour channel of an AlphaColour
c
,
simply composite c
over black.
c `over` (mempty :: Colour a)
ColourOps AlphaColour | |
AffineSpace AlphaColour | |
Eq a => Eq (AlphaColour a) | |
(Fractional a, Read a) => Read (AlphaColour a) | |
Fractional a => Show (AlphaColour a) | |
Num a => Monoid (AlphaColour a) |
|
opaque :: Num a => Colour a -> AlphaColour aSource
Creates an opaque AlphaColour
from a Colour
.
withOpacity :: Num a => Colour a -> a -> AlphaColour aSource
Creates an AlphaColour
from a Colour
with a given opacity.
c `withOpacity` o == dissolve o (opaque c)
transparent :: Num a => AlphaColour aSource
This AlphaColour
is entirely transparent and has no associated
colour channel.
alphaColourConvert :: (Fractional b, Real a) => AlphaColour a -> AlphaColour bSource
Change the type used to represent the colour coordinates.
alphaChannel :: AlphaColour a -> aSource
Returns the opacity of an AlphaColour
.
Colour operations
These operations allow combine and modify existing colours
class AffineSpace f whereSource
affineCombo :: Num a => [(a, f a)] -> f a -> f aSource
Compute a affine Combination (weighted-average) of points. The last parameter will get the remaining weight. e.g.
affineCombo [(0.2,a), (0.3,b)] c == 0.2*a + 0.3*b + 0.4*c
Weights can be negative, or greater than 1.0; however, be aware that non-convex combinations may lead to out of gamut colours.
blend :: (Num a, AffineSpace f) => a -> f a -> f a -> f aSource
Compute the weighted average of two points. e.g.
blend 0.4 a b = 0.4*a + 0.6*b
The weight can be negative, or greater than 1.0; however, be aware that non-convex combinations may lead to out of gamut colours.
over :: Num a => AlphaColour a -> f a -> f aSource
c1 `over` c2
returns the Colour
created by compositing the
AlphaColour
c1
over c2
, which may be either a Colour
or
AlphaColour
.
darken :: Num a => a -> f a -> f aSource
darken s c
blends a colour with black without changing it's opacity.
For Colour
, darken s c = blend s c mempty
dissolve :: Num a => a -> AlphaColour a -> AlphaColour aSource
Returns an AlphaColour
more transparent by a factor of o
.
atop :: Fractional a => AlphaColour a -> AlphaColour a -> AlphaColour aSource
c1 `atop` c2
returns the AlphaColour
produced by covering
the portion of c2
visible by c1
.
The resulting alpha channel is always the same as the alpha channel
of c2
.
c1 `atop` (opaque c2) == c1 `over` (opaque c2) AlphaChannel (c1 `atop` c2) == AlphaChannel c2