Drawing
7.1 Color
7.2 Pict
On this page:
rgb
hsv
rgb?
rgb-red
rgb-green
rgb-blue
rgb-alpha
rgb-hue
rgb-saturation
rgb-value
rgb->hsv
color?
->rgb
->color%
8.18.0.15

7.1 Color🔗

 (require toolbox/color) package: toolbox-draw-lib

This module provides structures and functions useful when working with colors.

Note that, technically, none of the structures provided by this module (or the ones provided by racket/draw) represent colors, only color coordinates. The specific color referred to by a given set of color coordinates depends on the color space they are interpreted in.

procedure

(rgb red green blue [alpha])  rgb?

  red : (real-in 0 1)
  green : (real-in 0 1)
  blue : (real-in 0 1)
  alpha : (real-in 0 1) = 1.0
Constructs an RGB color from the given components.

Example:
> (rgb 1 0 1 0.5)

(rgb 1.0 0.0 1.0 0.5)

procedure

(hsv hue saturation value [alpha])  rgb?

  hue : rational?
  saturation : (real-in 0 1)
  value : (real-in 0 1)
  alpha : (real-in 0 1) = 1.0
Constructs an RGB color from the given HSV coordinates. The hue component represents an angle, where 0.0 is interpreted as 0° and 1.0 is interpreted as 360°. The value of hue may be any rational number, and it will be interpreted modulo 1.

Examples:
> (hsv 0 1 1)

(rgb 1.0 0.0 0.0 1.0)

> (hsv 1/3 1 1)

(rgb 0.0 1.0 0.0 1.0)

> (hsv 2/3 1 1)

(rgb 0.0 0.0 1.0 1.0)

> (hsv 1/6 1 0.5)

(rgb 0.5 0.5 0.0 1.0)

procedure

(rgb? v)  boolean?

  v : any/c
Returns #t if v is an RGB color constructed with rgb or hsv, otherwise returns #f.

procedure

(rgb-red c)  (real-in 0 1)

  c : rgb?
Returns the red component of an RGB color.

procedure

(rgb-green c)  (real-in 0 1)

  c : rgb?
Returns the green component of an RGB color.

procedure

(rgb-blue c)  (real-in 0 1)

  c : rgb?
Returns the blue component of an RGB color.

procedure

(rgb-alpha c)  (real-in 0 1)

  c : rgb?
Returns the alpha component of an RGB color.

procedure

(rgb-hue c)  (and/c (>=/c 0) (</c 1))

  c : rgb?
Returns the hue component of the HSV coordinates for the given RGB color.

procedure

(rgb-saturation c)  (real-in 0 1)

  c : rgb?
Returns the saturation component of the HSV coordinates for the given RGB color.

procedure

(rgb-value c)  (real-in 0 1)

  c : rgb?
Returns the value component of the HSV coordinates for the given RGB color.

procedure

(rgb->hsv c)  
(and/c (>=/c 0) (</c 1))
(real-in 0 1)
(real-in 0 1)
  c : rgb?
Equivalent to (values (rgb-hue v) (rgb-saturation v) (rgb-value v)), except that rgb->hsv can be more efficient.

procedure

(color? v)  boolean?

  v : any/c
Returns #t if #f is an RGB color, a color% object, or a string corresponding to a color name in the-color-database.

procedure

(->rgb c)  rgb?

  c : color?
Returns an RGB color that represents the same color as c.

procedure

(->color% c)  (is-a?/c color%)

  c : color?
Returns an immutable color% object that represents the same color as c.