Module Archimedes.Color


module Color: sig .. end
Abstract representation of colors (suitable for RGBA).

type t 
Represent a color (immutable).
val rgb : float -> float -> float -> t
rgb r g b creates the color with transparency ~a, red component r, green component g and blue component b. All values must be between 0. and 1.; raises Invalid_argument otherwise.
val rgba : float -> float -> float -> float -> t
rgba r g b a creates the color with transparency ~a, red component r, green component g and blue component b. All values must be between 0. and 1.; raises Invalid_argument otherwise.
val hex : int -> t
hex c returns a color from its specification in "hexadecimal form", that is as 0xRRGGBB where R, G and B are hexadecimal digits giving the red, green, and blue components. It is the form used by Graphics.
val r : t -> float
Returns the red component of a color.
val g : t -> float
Returns the green component of a color.
val b : t -> float
Returns the blue component of a color.
val a : t -> float
Returns the transparency (alpha) component of a color.
val get_rgb : t -> float * float * float
Equivalent to (r t,g t,b t).
val get_rgba : t -> float * float * float * float
Equivalent to (r t,g t,b t, a t).
val luminance : t -> float
Returns the luminance of the color. See e.g. Wikipedia.

Predefined colors


val black : t
val red : t
val green : t
val blue : t
val yellow : t
val magenta : t
val cyan : t
val white : t
val dark_slate_grey : t

Shades of Blue


val deep_sky_blue : t
val dodger_blue : t
val aquamarine : t
val light_blue : t
val medium_blue : t
val navy_blue : t
val royal_blue : t

Shades of Brown


val burlywood : t
val chocolate : t
val tan : t

Shades of Green


val dark_green : t
val dark_olive_green : t
val forest_green : t
val green_yellow : t
val sea_green : t

Shades of Orange


val dark_orange : t
val peach_puff : t
val coral : t
val orange : t

Shades of Red


val hot_pink : t
val indian_red : t
val light_pink : t
val misty_rose : t
val orange_red : t
val firebrick : t

Shades of Violet


val dark_orchid : t
val lavender_blush : t
val plum : t
val orchid : t
val purple : t
val thistle : t

Shades of White


val antique_white : t
val old_lace : t
val ivory : t
val linen : t
val wheat : t
val white_smoke : t

Shades of Yellow


val lemon_chiffon : t
val light_goldenrod : t
val cornsilk : t
val gold : t

Shades of black


val light_gray : t
val gainsboro : t
val silver : t
val trolley_grey : t

Merging colors



type operator =
| Over (*Transparency and color components are mixed in such a way that it corresponds to putting the second color over the first*)
| Source (*First color completely ignored.*)
| Clear (*Inhibits all colors*)
| In (*RGB components as the second color, A component product of the two A components. So, a transparent color result if the first one was transparent.*)
| Out (*RGB components as the second color, A component product of the second A component with (1 - A) first component. So, a transparent color result if the first one was opaque.*)
| Atop (*Transparency of the first color is the final transparency; mixes RGB components.*)
| Dest (*Second color completely ignored. (<-> SOURCE)*)
| Dest_Over (*Transparency and color components are mixed in such a way that it corresponds to putting the first color over the second. (<-> OVER)*)
| Dest_In (*RGB components as the first color, A component product of the two A components. So, a transparent color result if the second one was transparent. (<-> IN)*)
| Dest_Out (*RGB components as the first color, A component product of the first A component with (1 - A) second component. So, a transparent color result if the second one was opaque. (<-> OUT)*)
| Dest_Atop (*Transparency of the second color is the final transparency; mixes RGB components. (<-> ATOP)*)
| Xor (*Same mix of color than OVER, but transparency will be more important.*)
| Add (*RGB components: ponderated sum of RGB components, with transparency. Resulting A is the sum of transparencies (bounded to 1. if necessary).*)
| Saturate (*Same as ADD, but the sum for RGB components shrinks the ponderation the first color components (coeff: min (first A, 1 - second A))*)
Different ways of merging colors. See http://cairographics.org/operators/ for more explanations.
val add : ?op:operator ->
t -> t -> t
Adds the first color to the second color, according to the operator op (default : Over).