Module Hugin.Color
Perceptually uniform OKLCH colors.
Perceptually uniform colors.
Colors are represented internally in the OKLCH color space. All operations (lighten, darken, mix) produce perceptually uniform results: equal numerical steps yield equal perceived differences.
Constructors accept common input formats (sRGB, hex) and convert to OKLCH on creation. The reverse conversion to_rgba is called only at render time.
Types
The type for colors in OKLCH space. Components are lightness [0, 1], chroma [0, ~0.4], hue [0, 360), and alpha [0, 1].
Constructors
val oklch : l:float -> c:float -> h:float -> unit -> toklch ~l ~c ~h () is the fully opaque OKLCH color with lightness l, chroma c, and hue h (in degrees).
val oklcha : l:float -> c:float -> h:float -> a:float -> unit -> toklcha ~l ~c ~h ~a () is like oklch with alpha a.
val rgb : r:float -> g:float -> b:float -> unit -> trgb ~r ~g ~b () is the fully opaque color with sRGB components r, g, b in [0, 1], converted to OKLCH.
val rgba : r:float -> g:float -> b:float -> a:float -> unit -> trgba ~r ~g ~b ~a () is like rgb with alpha a.
val hex : string -> thex s is the color parsed from the hex string s. Accepts "#RRGGBB" and "#RRGGBBAA" formats.
Raises Invalid_argument if s is not a valid hex color.
Accessors
val lightness : t -> floatlightness c is the OKLCH lightness of c in [0, 1].
val chroma : t -> floatchroma c is the OKLCH chroma of c in [0, ~0.4].
val hue : t -> floathue c is the OKLCH hue of c in degrees [0, 360).
val alpha : t -> floatalpha c is the alpha of c in [0, 1].
Converting
val to_rgba : t -> float * float * float * floatto_rgba c is (r, g, b, a) with sRGB components in [0, 1]. Values are clamped to the sRGB gamut.
Operations
lighten amount c is c with lightness increased by amount, clamped to [0, 1].
darken amount c is c with lightness decreased by amount, clamped to [0, 1].
mix ratio a b is the perceptual blend of a and b. ratio is the interpolation factor: 0.0 gives a, 1.0 gives b. Hue is interpolated along the shortest arc.
Named colors
The default named colors follow the Okabe-Ito palette, designed to be distinguishable under all forms of color-vision deficiency.
val orange : tval sky_blue : tval green : tval yellow : tval blue : tval vermillion : tval purple : tval black : tval white : tval gray : tFormatting
val pp : Stdlib.Format.formatter -> t -> unitpp formats the color as oklch(L C H / A).