| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Data.Colour
Description
Colour representations and combinations.
Synopsis
- data Colour
- pattern Colour :: Double -> Double -> Double -> Double -> Colour
- validColour :: Colour -> Bool
- validate :: Colour -> Maybe Colour
- trimColour :: Colour -> Colour
- showRGBA :: Colour -> ByteString
- showRGB :: Colour -> ByteString
- showOpacity :: Colour -> ByteString
- opac' :: Lens' Colour Double
- opac :: Colour -> Double
- rgb :: Colour -> Colour -> Colour
- palette :: Int -> Colour
- paletteO :: Int -> Double -> Colour
- transparent :: Colour
- black :: Colour
- white :: Colour
- light :: Colour
- dark :: Colour
- grey :: Double -> Double -> Colour
- data LCH a = LCH a a a
- lLCH' :: Lens' (LCH Double) Double
- cLCH' :: Lens' (LCH Double) Double
- hLCH' :: Lens' (LCH Double) Double
- data LCHA = LCHA' {}
- pattern LCHA :: Double -> Double -> Double -> Double -> LCHA
- lch' :: Lens' LCHA (LCH Double)
- alpha' :: Lens' LCHA Double
- data RGB3 a = RGB3 a a a
- rgbd' :: Iso' (RGB3 Double) (RGB3 Word8)
- rgb32colour' :: Iso' (RGB3 Double, Double) Colour
- data LAB a = LAB a a a
- lcha2colour' :: Iso' LCHA Colour
- xy2ch' :: Iso' (Double, Double) (Double, Double)
- mix :: Double -> Colour -> Colour -> Colour
- mixTrim :: Double -> Colour -> Colour -> Colour
- mixLCHA :: Double -> LCHA -> LCHA -> LCHA
- mixes :: Double -> [Colour] -> Colour
- greyed :: Colour -> Colour
- lightness' :: Lens' Colour Double
- chroma' :: Lens' Colour Double
- hue' :: Lens' Colour Double
- showSwatch :: Text -> Colour -> Text
- showSwatches :: Text -> Text -> [(Text, Colour)] -> Text
- rvRGB3 :: [RGB3 Double]
- rvColour :: [Colour]
- paletteR :: [Colour]
Colour
Colour type for the library: red, green, blue, opacity in [0,1].
Instances
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
Palette colours
palette :: Int -> Colour Source #
Select a Colour from the palette
>>>palette 0Colour 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.5Colour 1.745945680532727e-2 0.7278003002346461 0.7974711192713982 0.5
transparent :: Colour Source #
Zero-opacity black
>>>transparentColour 0.0 0.0 0.0 0.0
light
For lighter huds against a dark background ...
colourHudOptions light defaultHudOptions
>>>lightColour 0.94 0.94 0.94 1.0
dark
dark is hardcoded in most of the default options.
>>>darkColour 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.4Colour 0.5 0.5 0.5 0.4
LCH model
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 |
LCHA representation, including an alpha channel.
Constructors
| RGB3 a a a |
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
LAB colour representation. a is green-red and b is blue-yellow
Constructors
| LAB a a a |
lcha2colour' :: Iso' LCHA Colour Source #
LCHA to Colour lens
>>>c0 = Colour 0.78 0.36 0.02 1.00>>>view (re lcha2colour') c0LCHA' {_lch = LCH 0.5969891006896103 0.15793931531669247 49.191113810479784, _alpha = 1.0}
>>>view (re lcha2colour' % lcha2colour') c0Colour 0.7799971480660184 0.36002701529867864 2.0019279558778965e-2 1.0
>>>c1 = Colour 0.49 0.14 0.16 1>>>view (re lcha2colour') c1LCHA' {_lch = LCH 0.40115567099848914 0.12279066817938503 21.51476756026837, _alpha = 1.0}
>>>view (re lcha2colour' % lcha2colour') c1Colour 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
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>"