Module Convert.Color

Extended Color module with additional types and conversion functions.

include module type of Color
type gg = Gg.color
module type ColorRep = sig ... end
module Rgb : sig ... end
module Rgb_float : sig ... end
module Hsl : sig ... end
module Oklab : sig ... end
module Oklch : sig ... end
val of_hexstring : string -> gg option
val to_hexstring : gg -> string
val black : gg
val white : gg
val gray_tone : float -> gg
val rotate_hue : float -> gg -> gg
val complementary : gg -> gg
val lighten : float -> gg -> gg
val darken : float -> gg -> gg
val intensify : float -> gg -> gg
val desintensify : float -> gg -> gg
val lightness : gg -> float
val contrast_ratio : gg -> gg -> float
val is_light : gg -> bool
val readable : gg -> gg -> bool
val text_color : gg -> gg
val random : ?alpha:float -> ?light:float -> ?chroma:float -> unit -> gg
module Rgba : sig ... end

RGBA color type with integer components (0-255) and float alpha (0.0-1.0).

module Rgba' : sig ... end

RGBA color type with float components (0.0-1.0).

module Hsva : sig ... end

HSVA color type (Hue, Saturation, Value, Alpha).

val of_rgb : int -> int -> int -> Gg.v4

Create a color from RGB integer values (0-255).

  let red = Color.of_rgb 255 0 0
  • parameter r

    Red component (0-255)

  • parameter g

    Green component (0-255)

  • parameter b

    Blue component (0-255)

  • returns

    Gg.v4 color

val to_rgba : Gg.v4 -> Rgba.t

Convert a color to RGBA with integer components (0-255).

  let color = Gg.Color.v_srgb 0.8 0.3 0.2 in
  let rgba = Spectrum_tools.Convert.Color.to_rgba color in
  Printf.printf "R:%d G:%d B:%d A:%.2f\n" rgba.r rgba.g rgba.b rgba.a
  (* Output: R:204 G:77 B:51 A:1.00 *)
  • parameter color

    Color to convert

  • returns

    RGBA record with integer components

val to_rgba' : Gg.v4 -> Rgba'.t

Convert a color to RGBA with float components (0.0-1.0).

  let color = Gg.Color.v_srgb 0.8 0.3 0.2 in
  let rgba' = Spectrum_tools.Convert.Color.to_rgba' color in
  Printf.printf "R:%.3f G:%.3f B:%.3f A:%.3f\n"
    rgba'.r rgba'.g rgba'.b rgba'.a
  (* Output: R:0.800 G:0.300 B:0.200 A:1.000 *)
  • parameter color

    Color to convert

  • returns

    RGBA record with float components

val of_hsl : float -> float -> float -> Gg.v4

Create a color from HSL values.

  (* Create yellow: hue=60°, full saturation, medium lightness *)
  let yellow = Spectrum_tools.Convert.Color.of_hsl 60. 100. 50. in
  let rgba = Spectrum_tools.Convert.Color.to_rgba yellow in
  Printf.printf "RGB(%d, %d, %d)\n" rgba.r rgba.g rgba.b
  (* Output: RGB(255, 255, 0) *)
  (* Create a muted blue *)
  let muted_blue = Spectrum_tools.Convert.Color.of_hsl 210. 50. 60. in
  let rgba = Spectrum_tools.Convert.Color.to_rgba muted_blue in
  Printf.printf "RGB(%d, %d, %d)\n" rgba.r rgba.g rgba.b
  • parameter h

    Hue in degrees (0-360)

  • parameter s

    Saturation (0-100)

  • parameter l

    Lightness (0-100)

  • returns

    Gg.v4 color

val to_hsva : Gg.v4 -> Hsva.t

Convert a color to HSVA representation.

  let red = Gg.Color.v_srgb 1.0 0.0 0.0 in
  let hsva = Spectrum_tools.Convert.Color.to_hsva red in
  Printf.printf "H:%.1f S:%.1f V:%.1f A:%.2f\n"
    hsva.h hsva.s hsva.v hsva.a
  (* Output: H:0.0 S:100.0 V:100.0 A:1.00 *)
  (* Convert an arbitrary color *)
  let color = Gg.Color.v_srgb 0.6 0.8 0.4 in
  let hsva = Spectrum_tools.Convert.Color.to_hsva color in
  Printf.printf "Hue: %.1f°\n" hsva.h
  • parameter color

    Color to convert

  • returns

    HSVA record with h (0-360), s (0-100), v (0-100), a (0.0-1.0)