package color
Library
Module
Module type
Parameter
Class
Class type
This module deals with colors.
module type ColorRep = sig ... end
Classic RedGreenBlue (& optional alpha) representation, closely matching the way screens display colors.
Hue, Saturation, Lightness. More intuitive to work with than Rgb
.
A color space that is ok. See the author's blog for more info.
The polar version of Oklab
. See mozilla's page on it for more info. Arguably the easiest space to work with, as it closely match our perception of colors.
val of_hexstring : string -> gg option
Parse a hexadecimal color code. Handles short format like #rgb
or long format #rrggbb
. Short format #abc
corresponds to long format #aabbcc
.
val to_hexstring : gg -> string
Converts a color to its hexadecimal representation. The alpha channel is not represented.
val black : gg
Pure black
val white : gg
Pure white
val gray_tone : float -> gg
Creates a gray tone from light values (0.0 -> black, 1.0 -> white)
val lightness : gg -> float
The perceived lightness of any color, with 0. for the darkest black and 1. for the lightest white.
Contrast ratio between two colors. It is a value that can range from 1. to 21. https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef W3 reference
}
val is_light : gg -> bool
Checks whether a color is perceived as a light color.
Checks if text of one color is readable on a background of the second color. A minimum contrast ratio of 4.5 is recommended to ensure that text is readable on a given background. W3 reference
Returns a readable foreground text color (picks between black or white) for a given background color
val random : ?alpha:float -> ?light:float -> ?chroma:float -> unit -> gg
Picks a color with a random hue. Uses a default "full-light" chroma and lightness, and full opacity.