package color

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module ColorSource

This module deals with colors.

Representation of a color.

Sourcemodule Hsla : sig ... end
Sourcemodule Rgba' : sig ... end
Sourcemodule Rgba : sig ... end
Sourceval of_rgba : int -> int -> int -> float -> t

Creates a color from integer RGB values between 0 and 255 and a floating point alpha value between 0.0 and 1.0. Algorithm adapted from: https://en.wikipedia.org/wiki/HSL_and_HSV

Sourceval of_rgb : int -> int -> int -> t

Creates a color from RGB values between 0 and 255.

Sourceval of_rgba' : float -> float -> float -> float -> t

Creates a color from RGB and alpha values between 0.0 and 1.0

Sourceval of_rgb' : float -> float -> float -> t

Creates a color from RGB values between 0.0 and 1.0

Sourceval of_hsla : float -> float -> float -> float -> t

Creates a color from Hue, Saturation, Lightness and Alpha values. Hue is in degrees, a float value between 0.0 and 360.0. Saturation, Lightness and Alpha are float values between 0.0 and 1.0

Sourceval of_hsl : float -> float -> float -> t

Creates a color from Hue, Saturation and Lightness. Hue is in degrees, a float value between 0.0 and 360.0. Saturation and Lightness are float values between 0.0 and 1.0

Sourceval of_hexstring : string -> t 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_hsla : t -> Hsla.t

Converts a color to its Hue, Saturation, Lightness and Alpha values.

Sourceval to_rgba' : t -> Rgba'.t

Converts a color to its rgba value. All values are floats between 0.0 and 1.0

Sourceval to_rgba : t -> Rgba.t

Converts a color to its rgba value. RGB values are integers in the range of 0 to 255. The alpha channel is a float between 0.0 and 1.0

Sourceval to_hexstring : t -> string

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

Sourceval to_css_hsla : t -> string

CSS representation of the color in hsl(..) or hsla(..) form.

Sourceval to_css_rgba : t -> string

CSS representation of the color in rgb(..) or rgba(..) form.

Sourceval black : t

Pure black

Sourceval white : t

Pure white

Sourceval gray_tone : float -> t

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

Sourceval rotate_hue : float -> t -> t

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

Sourceval complementary : t -> t

Gets complementary color by rotating hue by 180°

Sourceval lighten : float -> t -> t

Lightens a color by adding an amount to the lightness channel

Sourceval darken : float -> t -> t

Darkens a color by subtracing an amount to the lightness channel

Sourceval saturate : float -> t -> t

Increases the saturation of a color

Sourceval desaturate : float -> t -> t

Decreases the saturation of a color

Sourceval brightness : t -> float

The perceived brightness of a color. https://www.w3.org/TR/AERT/#color-contrast

Sourceval relative_luminance : t -> float

The relative brightness of any color, normalized to 0. for darkest black and 1. for lightest white. https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef

Sourceval contrast_ratio : t -> t -> 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/#con<Paste>

Sourceval light : t -> bool

Checks whether a color is perceived as a light color.

Sourceval readable : t -> t -> 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. https://www.w3.org/TR/WCAG20-TECHS/G18.html

Sourceval text_color : t -> t

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