package archimedes

  1. Overview
  2. Docs

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 int : int -> t

int c returns a color from its specification as an integer whose value is 0xRRGGBB where R, G and B are hexadecimal digits giving the red, green, and blue components of that color.

It is the form used by Graphics.

val hue : float -> t

hue h returns a color of given hue h in the interval [0 .. 360.[ (h is reduced modulo 360.) and of maximal luminance.

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
val colors : t list

The list of all predefined colors.

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 =
  1. | Over
    (*

    Transparency and color components are mixed in such a way that it corresponds to putting the second color over the first

    *)
  2. | Source
    (*

    First color completely ignored.

    *)
  3. | Clear
    (*

    Inhibits all colors

    *)
  4. | 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.

    *)
  5. | 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.

    *)
  6. | Atop
    (*

    Transparency of the first color is the final transparency; mixes RGB components.

    *)
  7. | Dest
    (*

    Second color completely ignored. (<-> SOURCE)

    *)
  8. | Dest_Over
    (*

    Transparency and color components are mixed in such a way that it corresponds to putting the first color over the second. (<-> OVER)

    *)
  9. | 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)

    *)
  10. | 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)

    *)
  11. | Dest_Atop
    (*

    Transparency of the second color is the final transparency; mixes RGB components. (<-> ATOP)

    *)
  12. | Xor
    (*

    Same mix of color than OVER, but transparency will be more important.

    *)
  13. | Add
    (*

    RGB components: ponderated sum of RGB components, with transparency. Resulting A is the sum of transparencies (bounded to 1. if necessary).

    *)
  14. | 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).

Variations of a given color

val lighten : t -> float -> t

lighten c v Lighten the color c of v percent. 0 corresponds to the same color, 1 corresponds to the white color.

val darken : t -> float -> t

darken c v Darken the color c of v percent. 0 correspond to the same color, 1 corresponds to the black color.

val highest_contrast_bw : t -> t

returns black or white depending on which of the two is better to write on the given color.

OCaml

Innovation. Community. Security.