Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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
- hex :: Colour -> Text
- rgb :: Colour -> Colour -> Colour
- toHex :: Colour -> Text
- fromHex :: Text -> Either Text (Color RGB Double)
- unsafeFromHex :: Text -> Color RGB Double
- palette :: Int -> Colour
- paletteO :: Int -> Double -> Colour
- transparent :: Colour
- black :: Colour
- white :: Colour
- light :: Colour
- dark :: Colour
- grey :: Double -> Double -> Colour
- newtype LCH a = LCH' {}
- pattern LCH :: a -> a -> a -> LCH 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
- newtype RGB3 a = RGB3' {}
- pattern RGB3 :: a -> a -> a -> RGB3 a
- rgbd' :: Iso' (RGB3 Double) (RGB3 Word8)
- rgb32colour' :: Iso' (RGB3 Double, Double) Colour
- newtype LAB a = LAB' {}
- pattern LAB :: a -> a -> a -> LAB 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, wrapping Color
.
pattern Colour :: Double -> Double -> Double -> Double -> Colour Source #
Constructor pattern.
Colour red green blue alpha
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.00 1.00 1.00 1.00
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 0
Colour 0.02 0.73 0.80 1.00
paletteO :: Int -> Double -> Colour Source #
Select a Colour from the palette with a specified opacity
>>>
paletteO 0 0.5
Colour 0.02 0.73 0.80 0.50
transparent :: Colour Source #
Zero-opacity black
>>>
transparent
Colour 0.00 0.00 0.00 0.00
light
For lighter huds against a dark background ...
colourHudOptions light defaultHudOptions
>>>
light
Colour 0.94 0.94 0.94 1.00
dark
dark is hardcoded in most of the default options.
>>>
dark
Colour 0.05 0.05 0.05 1.00
grey :: Double -> Double -> Colour Source #
Grey(scale) colour inputting lightness and opacity.
>>>
grey 0.5 0.4
Colour 0.50 0.50 0.50 0.40
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
LCHA representation, including an alpha channel.
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
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' {lchArray = [0.5969891006896103, 0.15793931531669247, 49.191113810479784]}, _alpha = 1.0}
>>>
view (re lcha2colour' % lcha2colour') c0
Colour 0.78 0.36 0.02 1.00
>>>
c1 = Colour 0.49 0.14 0.16 1
>>>
view (re lcha2colour') c1
LCHA' {_lch = LCH' {lchArray = [0.40115567099848914, 0.12279066817938503, 21.51476756026837]}, _alpha = 1.0}
>>>
view (re lcha2colour' % lcha2colour') c1
Colour 0.49 0.14 0.16 1.00
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 -0.09 0.48 0.45 0.60
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.14 0.44 0.59 0.60
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.00 0.48 0.45 0.60
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.00 0.00 0.00 1.00
>>>
mixes 1 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.99 0.99 0.99 1.00
>>>
mixes 0.6 [black, (Colour 0.2 0.6 0.8 0.5), white]
Colour 0.42 0.67 0.86 0.60
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.65 0.65 0.65 0.40
lightness' :: Lens' Colour Double Source #
Lightness lens
>>>
over lightness' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.22 0.52 0.62 0.40
chroma' :: Lens' Colour Double Source #
Chromacity lens
>>>
over chroma' (*0.8) (Colour 0.4 0.7 0.8 0.4)
Colour 0.46 0.69 0.77 0.40
hue' :: Lens' Colour Double Source #
Hue lens
>>>
over hue' (+180) (Colour 0.4 0.7 0.8 0.4)
Colour 0.83 0.58 0.49 0.40
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>"