chart-svg
Safe HaskellNone
LanguageGHC2024

Data.Colour

Description

Colour representations and combinations.

Synopsis

Colour

data Colour Source #

Colour type for the library: red, green, blue, opacity in [0,1].

Instances

Instances details
Eq Colour Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: Colour -> Colour -> Bool #

(/=) :: Colour -> Colour -> Bool #

Data Colour Source # 
Instance details

Defined in Data.Colour

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Colour -> c Colour #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Colour #

toConstr :: Colour -> Constr #

dataTypeOf :: Colour -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Colour) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Colour) #

gmapT :: (forall b. Data b => b -> b) -> Colour -> Colour #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Colour -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Colour -> r #

gmapQ :: (forall d. Data d => d -> u) -> Colour -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Colour -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Colour -> m Colour #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Colour -> m Colour #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Colour -> m Colour #

Generic Colour Source # 
Instance details

Defined in Data.Colour

Methods

from :: Colour -> Rep Colour x #

to :: Rep Colour x -> Colour #

Read Colour Source # 
Instance details

Defined in Data.Colour

Show Colour Source # 
Instance details

Defined in Data.Colour

Uniform Colour Source # 
Instance details

Defined in Data.Colour

Methods

uniformM :: StatefulGen g m => g -> m Colour #

type Rep Colour Source # 
Instance details

Defined in Data.Colour

pattern Colour :: Double -> Double -> Double -> Double -> Colour Source #

validColour :: Colour -> Bool Source #

Is Colour in-gamut?

>>> validColour (Colour 1 1 1.01 1)
False

validate :: Colour -> Maybe Colour Source #

Validate that the Colout is in-gamut.

>>> validate (Colour 1 1 1.01 1)
Nothing

trimColour :: Colour -> Colour Source #

Trim colour back to gamut.

>>> trimColour (Colour 1 1 1.01 1)
Colour 1.0 1.0 1.0 1.0

showRGBA :: Colour -> ByteString Source #

CSS-style representation

showRGB :: Colour -> ByteString Source #

CSS-style representation

showOpacity :: Colour -> ByteString Source #

CSS-style representation

opac' :: Lens' Colour Double Source #

lens for opacity (or alpha channel)

opac :: Colour -> Double Source #

Opacity or alpha

rgb :: Colour -> Colour -> Colour Source #

Sets RGB color but not opacity

Palette colours

palette :: Int -> Colour Source #

Select a Colour from the palette

>>> palette 0
Colour 1.745945680532727e-2 0.7278003002346461 0.7974711192713982 1.0

paletteO :: Int -> Double -> Colour Source #

Select a Colour from the palette with a specified opacity

>>> paletteO 0 0.5
Colour 1.745945680532727e-2 0.7278003002346461 0.7974711192713982 0.5

transparent :: Colour Source #

Zero-opacity black

>>> transparent
Colour 0.0 0.0 0.0 0.0

black :: Colour Source #

black

>>> black
Colour 0.0 0.0 0.0 1.0

white :: Colour Source #

white

>>> white
Colour 0.99 0.99 0.99 1.0

light :: Colour Source #

light

For lighter huds against a dark background ...

colourHudOptions light defaultHudOptions
>>> light
Colour 0.94 0.94 0.94 1.0

dark :: Colour Source #

dark

dark is hardcoded in most of the default options.

>>> dark
Colour 5.0e-2 5.0e-2 5.0e-2 1.0

grey :: Double -> Double -> Colour Source #

Grey(scale) colour inputting lightness and opacity.

>>> grey 0.5 0.4
Colour 0.5 0.5 0.5 0.4

LCH model

data LCH a Source #

LCH colour representation

oklab is a colour space being written into CSS specifications, that attempts to be ok at human-consistent colour representation. See:

The type is represented by three elements:

L: Lightness ranging from 0 (LCH 0 _ _ is black) to 1 (LCH 1 _ _ is white)

C: Chromacity, which ranges from 0 to around 0.32 or so.

H: Hue, which ranges from 0 to 360

Constructors

LCH a a a 

Instances

Instances details
Functor LCH Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> LCH a -> LCH b #

(<$) :: a -> LCH b -> LCH a #

Eq a => Eq (LCH a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LCH a -> LCH a -> Bool #

(/=) :: LCH a -> LCH a -> Bool #

Read a => Read (LCH a) Source # 
Instance details

Defined in Data.Colour

Show a => Show (LCH a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LCH a -> ShowS #

show :: LCH a -> String #

showList :: [LCH a] -> ShowS #

lLCH' :: Lens' (LCH Double) Double Source #

Lightness lens for LCH

cLCH' :: Lens' (LCH Double) Double Source #

Chromacity lens for LCH

hLCH' :: Lens' (LCH Double) Double Source #

Hue lens for LCH

data LCHA Source #

LCHA representation, including an alpha channel.

Constructors

LCHA' 

Fields

Instances

Instances details
Eq LCHA Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LCHA -> LCHA -> Bool #

(/=) :: LCHA -> LCHA -> Bool #

Read LCHA Source # 
Instance details

Defined in Data.Colour

Show LCHA Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LCHA -> ShowS #

show :: LCHA -> String #

showList :: [LCHA] -> ShowS #

pattern LCHA :: Double -> Double -> Double -> Double -> LCHA Source #

LCHA pattern

lch' :: Lens' LCHA (LCH Double) Source #

LCH lens for LCHA

alpha' :: Lens' LCHA Double Source #

Alpha lens for LCHA

data RGB3 a Source #

A type to represent the RGB triple, useful as an intermediary between Colour and LCHA

Constructors

RGB3 a a a 

Instances

Instances details
Functor RGB3 Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> RGB3 a -> RGB3 b #

(<$) :: a -> RGB3 b -> RGB3 a #

Eq a => Eq (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: RGB3 a -> RGB3 a -> Bool #

(/=) :: RGB3 a -> RGB3 a -> Bool #

Read a => Read (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Show a => Show (RGB3 a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> RGB3 a -> ShowS #

show :: RGB3 a -> String #

showList :: [RGB3 a] -> ShowS #

Uniform (RGB3 Double) Source # 
Instance details

Defined in Data.Colour

Methods

uniformM :: StatefulGen g m => g -> m (RGB3 Double) #

rgbd' :: Iso' (RGB3 Double) (RGB3 Word8) Source #

Lens for conversion between Double and Word8 RGB triples.

rgb32colour' :: Iso' (RGB3 Double, Double) Colour Source #

Lens for conversion between an (RGB3, alpha) pair and Colour

data LAB a Source #

LAB colour representation. a is green-red and b is blue-yellow

Constructors

LAB a a a 

Instances

Instances details
Functor LAB Source # 
Instance details

Defined in Data.Colour

Methods

fmap :: (a -> b) -> LAB a -> LAB b #

(<$) :: a -> LAB b -> LAB a #

Eq a => Eq (LAB a) Source # 
Instance details

Defined in Data.Colour

Methods

(==) :: LAB a -> LAB a -> Bool #

(/=) :: LAB a -> LAB a -> Bool #

Read a => Read (LAB a) Source # 
Instance details

Defined in Data.Colour

Show a => Show (LAB a) Source # 
Instance details

Defined in Data.Colour

Methods

showsPrec :: Int -> LAB a -> ShowS #

show :: LAB a -> String #

showList :: [LAB a] -> ShowS #

lcha2colour' :: Iso' LCHA Colour Source #

LCHA to Colour lens

>>> c0 = Colour 0.78 0.36 0.02 1.00
>>> view (re lcha2colour') c0
LCHA' {_lch = LCH 0.5969891006896103 0.15793931531669247 49.191113810479784, _alpha = 1.0}
>>> view (re lcha2colour' % lcha2colour') c0
Colour 0.7799971480660184 0.36002701529867864 2.0019279558778965e-2 1.0
>>> c1 = Colour 0.49 0.14 0.16 1
>>> view (re lcha2colour') c1
LCHA' {_lch = LCH 0.40115567099848914 0.12279066817938503 21.51476756026837, _alpha = 1.0}
>>> view (re lcha2colour' % lcha2colour') c1
Colour 0.4899986884783269 0.14002320537292892 0.16000148010470103 1.0

xy2ch' :: Iso' (Double, Double) (Double, Double) Source #

Lens between generic XY color representations and CH ones, which are polar versions of the XY.

mixins

mix :: Double -> Colour -> Colour -> Colour Source #

Mix 2 colours, using the oklch model.

This may not always be what you expect. One example is mixing black and another colour:

>>> mix 0.8 (Colour 0 0 0 1) (Colour 0.2 0.6 0.8 0.5)
Colour -9.09931254727234e-2 0.4761749098994677 0.448853534456995 0.6

The mix has gone out of gamut because we are swishing through hue mixes.

In this case, settting the hue on the black colour within the LCH contruct helps:

>>> betterblack = set (lch' % hLCH') (view hue' (Colour 0.2 0.6 0.8 0.5)) (review lcha2colour' black)
>>> view lcha2colour' $ mixLCHA 0.8 betterblack (review lcha2colour' $ Colour 0.2 0.6 0.8 0.5)
Colour 0.13796457900126569 0.4405742858448237 0.5918899179589158 0.6

mixTrim :: Double -> Colour -> Colour -> Colour Source #

Mix 2 colours, using the oklch model, trimming the reult back to in-gamut.

>>> mixTrim 0.8 (Colour 0 0 0 1) (Colour 0.2 0.6 0.8 0.5)
Colour 0.0 0.4761749098994677 0.448853534456995 0.6

mixLCHA :: Double -> LCHA -> LCHA -> LCHA Source #

Mix two LCHA specified colours.

mixes :: Double -> [Colour] -> Colour Source #

Interpolate across a list of Colours, with input being in Range 0 1

>>> mixes 0 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.0 0.0 0.0 1.0
>>> mixes 1 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.990006487680139 0.9900235338998363 0.9900069013222627 1.0
>>> mixes 0.6 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.42326087775523685 0.6697483588860055 0.8551643643270169 0.6

greyed :: Colour -> Colour Source #

Convert a colour to grayscale with the same lightness.

>>> greyed (Colour 0.4 0.7 0.8 0.4)
Colour 0.6512795852495924 0.6512170310301152 0.6509875897399052 0.4

lightness' :: Lens' Colour Double Source #

Lightness lens

>>> over lightness' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.2164521158395537 0.52366760947314 0.6192919592501553 0.4

chroma' :: Lens' Colour Double Source #

Chromacity lens

>>> over chroma' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.4617871186277957 0.6915093453577127 0.7707963054467656 0.4

hue' :: Lens' Colour Double Source #

Hue lens

>>> over hue' (+180) (Colour 0.4 0.7 0.8 0.4)
Colour 0.8320015577891179 0.5836799066928026 0.48874314193645124 0.4

showSwatch :: Text -> Colour -> Text Source #

Html element to display colours

>>> showSwatch "swatch" dark
"<div class=swatch style=\"background:rgba(5%, 5%, 5%, 1.00);\">swatch</div>"

showSwatches :: Text -> Text -> [(Text, Colour)] -> Text Source #

Show multiple colors with embedded text.

rvRGB3 :: [RGB3 Double] Source #

Random list of RGB3s

rvColour :: [Colour] Source #

Random list of Colours

paletteR :: [Colour] Source #

Random Colours with an opacity of 1 that are not too extreme in terms of lightness or chromacity.