package color

  1. Overview
  2. Docs

Module ColorSource

This module deals with colors.

Sourcetype gg = Gg.color

Standard representation of a color.

Sourcemodule type ColorRep = sig ... end
Sourcemodule Rgb : ColorRep with type param = int

Classic RedGreenBlue (& optional alpha) representation, closely matching the way screens display colors.

Sourcemodule Rgb_float : ColorRep with type param = float

Same as Rgb, but with float values.

Sourcemodule Hsl : ColorRep with type param = float

Hue, Saturation, Lightness. More intuitive to work with than Rgb.

Sourcemodule Oklab : ColorRep with type param = float

A color space that is ok. See the author's blog for more info.

Sourcemodule Oklch : ColorRep with type param = float

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.

Sourceval 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.

Sourceval to_hexstring : gg -> string

Converts a color to its hexadecimal representation. The alpha channel is not represented.

Sourceval black : gg

Pure black

Sourceval white : gg

Pure white

Sourceval gray_tone : float -> gg

Creates a gray tone from light values (0.0 -> black, 1.0 -> white)

Sourceval rotate_hue : float -> gg -> gg

Rotates the hue of a Color by some angle (in degrees)

Sourceval complementary : gg -> gg

Gets complementary color by rotating hue by 180°

Sourceval lighten : float -> gg -> gg

Lightens a color by adding an amount to the lightness channel

Sourceval darken : float -> gg -> gg

Darkens a color by subtracting an amount to the lightness channel

Sourceval intensify : float -> gg -> gg

Increases the chroma of a color

Sourceval desintensify : float -> gg -> gg

Decreases the chroma of a color

Sourceval lightness : gg -> float

The perceived lightness of any color, with 0. for the darkest black and 1. for the lightest white.

Sourceval contrast_ratio : gg -> gg -> float

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

}

Sourceval is_light : gg -> bool

Checks whether a color is perceived as a light color.

Sourceval readable : gg -> gg -> bool

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

Sourceval text_color : gg -> gg

Returns a readable foreground text color (picks between black or white) for a given background color

Sourceval 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.

OCaml

Innovation. Community. Security.