Module Stk.Color

Colors.

type t

A color.

module Map : Stdlib.Map.S with type key = t
val compare : t -> t -> int
val pp : Stdlib.Format.formatter -> t -> unit
val to_int8s : t -> int * int * int * int

to_int8s color returns (red, green, blue, alpha) components of color.

val of_rgba : int -> int -> int -> int -> t

of_rgba r g b a returns a color from the given components.

val of_rgba_0_1 : float -> float -> float -> float -> t

of_rgba_0_1 r g b a returns a color from the given components as floats. Each component must be between 0. and 1. and is multiplicated by 255 to get the value on one byte for this component. Out of bounds values are corrected to be at least 0 and at most 255.

val of_int32 : int32 -> t

Return a color from a int32, with bytes representing red, green, blue and alpha (opacity). For example 0xaabbccddl has aa for red, bb for green, cc for blue and dd for opacity;

val to_sdl_color : t -> Tsdl.Sdl.color

to_sdl_color n creates a Tsdl.Sdl.color from a color.

val of_hexa : string -> t

Returns a color from a hexadecimal string representation. With each character being 0..9 or a|A..f|F, accepted forms are:

  • "rgb", mapped to (rr,gg,bb,FF),
  • "rgba", mapped to (rr,gg,bb,aa),
  • "rrggbb", mapped to (rr,gg,bb,FF),
  • any other string s which can be parsed by Int32.of_string ("0x"^s).

Raises Failure if the representation is invalid.

val transparent : t

The transparent color.

val transparent_int8s : int * int * int * int

Transparent color as (r,g,b,a) bytes.

val transparent_sdl : Tsdl.Sdl.color

Transparent SDL color.

val to_string : ?as_name:bool -> t -> string

to_string c returns a string representation of color c in the form 0xhhhhhhhh (classical hexadecimal values for components red, green, blue and alpha). Optional parameter as_name (default:true) indicates if the name of the color must be returned rather than its hexadecimal representation, when a name is registered for this color (see register).

val of_string : string -> t

of_string s returns the color associated to the given string (case-sensitive) in the registered colors. If no color with this name is found, then if s begin with '#', the rest of the string is parsed with of_hexa. If it fails or if the string does not start with '#', the black color is returned.

Registered colors

val register : string -> t -> unit

register name c registers color c with name so that it can be parsed (see of_string) and printed (see to_string using this name. If a color with the same name was already registered, a warning is issued and the new binding replaces the previous one. Same if another name was already associated to c.

val registered : unit -> (string * t) list

registered () return the list of registered colors in the form (name, color).

val random : unit -> t

random () returns a random color among the registered colors.

val ocf_wrapper : t Ocf.wrapper

Ocf.wrapper wrapper for a color.

Predefined colors

The following colors are already registered. These named colors corresponds to the SVG color specification.

val aliceblue : t
val antiquewhite : t
val aqua : t
val aquamarine : t
val azure : t
val beige : t
val bisque : t
val black : t
val blanchedalmond : t
val blue : t
val blueviolet : t
val brown : t
val burlywood : t
val cadetblue : t
val chartreuse : t
val chocolate : t
val coral : t
val cornflowerblue : t
val cornsilk : t
val crimson : t
val cyan : t
val darkblue : t
val darkcyan : t
val darkgoldenrod : t
val darkgray : t
val darkgreen : t
val darkgrey : t
val darkkhaki : t
val darkmagenta : t
val darkolivegreen : t
val darkorange : t
val darkorchid : t
val darkred : t
val darksalmon : t
val darkseagreen : t
val darkslateblue : t
val darkslategray : t
val darkslategrey : t
val darkturquoise : t
val darkviolet : t
val deeppink : t
val deepskyblue : t
val dimgray : t
val dimgrey : t
val dodgerblue : t
val firebrick : t
val floralwhite : t
val forestgreen : t
val fuchsia : t
val gainsboro : t
val ghostwhite : t
val gold : t
val goldenrod : t
val gray : t
val green : t
val greenyellow : t
val grey : t
val honeydew : t
val hotpink : t
val indianred : t
val indigo : t
val ivory : t
val khaki : t
val lavender : t
val lavenderblush : t
val lawngreen : t
val lemonchiffon : t
val lightblue : t
val lightcoral : t
val lightcyan : t
val lightgoldenrodyellow : t
val lightgray : t
val lightgreen : t
val lightgrey : t
val lightpink : t
val lightsalmon : t
val lightseagreen : t
val lightskyblue : t
val lightslategray : t
val lightslategrey : t
val lightsteelblue : t
val lightyellow : t
val lime : t
val limegreen : t
val linen : t
val magenta : t
val maroon : t
val mediumaquamarine : t
val mediumblue : t
val mediumorchid : t
val mediumpurple : t
val mediumseagreen : t
val mediumslateblue : t
val mediumspringgreen : t
val mediumturquoise : t
val mediumvioletred : t
val midnightblue : t
val mintcream : t
val mistyrose : t
val moccasin : t
val navajowhite : t
val navy : t
val oldlace : t
val olive : t
val olivedrab : t
val orange : t
val orangered : t
val orchid : t
val palegoldenrod : t
val palegreen : t
val paleturquoise : t
val palevioletred : t
val papayawhip : t
val peachpuff : t
val peru : t
val pink : t
val plum : t
val powderblue : t
val purple : t
val red : t
val rosybrown : t
val royalblue : t
val saddlebrown : t
val salmon : t
val sandybrown : t
val seagreen : t
val seashell : t
val sienna : t
val silver : t
val skyblue : t
val slateblue : t
val slategray : t
val slategrey : t
val snow : t
val springgreen : t
val steelblue : t
val tan : t
val teal : t
val thistle : t
val tomato : t
val turquoise : t
val violet : t
val wheat : t
val white : t
val whitesmoke : t
val yellow : t
val yellowgreen : t