Convert.ColorExtended Color module with additional types and conversion functions.
include module type of Colormodule type ColorRep = sig ... endmodule Rgb : sig ... endmodule Rgb_float : sig ... endmodule Hsl : sig ... endmodule Oklab : sig ... endmodule Oklch : sig ... endval of_hexstring : string -> gg optionval to_hexstring : gg -> stringval black : ggval white : ggval gray_tone : float -> ggval lightness : gg -> floatval is_light : gg -> boolval random : ?alpha:float -> ?light:float -> ?chroma:float -> unit -> ggmodule Rgba : sig ... endRGBA color type with integer components (0-255) and float alpha (0.0-1.0).
module Rgba' : sig ... endRGBA color type with float components (0.0-1.0).
module Hsva : sig ... endHSVA color type (Hue, Saturation, Value, Alpha).
Create a color from RGB integer values (0-255).
let red = Color.of_rgb 255 0 0val to_rgba : Gg.v4 -> Rgba.tConvert 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 *)val to_rgba' : Gg.v4 -> Rgba'.tConvert 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 *)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.bval to_hsva : Gg.v4 -> Hsva.tConvert 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