6 color%

▼ |  | The Racket Drawing Toolkit

1 | Overview
2 | bitmap%
3 | bitmap-dc%
4 | brush%
5 | brush-list%
6 | color%
7 | color-database<%>
8 | dc<%>
9 | dc-path%
10 | font%
11 | font-list%
12 | font-name-directory<%>
13 | gl-config%
14 | gl-context<%>
15 | linear-gradient%
16 | pdf-dc%
17 | pen%
18 | pen-list%
19 | point%
20 | post-script-dc%
21 | ps-setup%
22 | radial-gradient%
23 | record-dc%
24 | region%
25 | svg-dc%
26 | Drawing Functions
27 | Drawing Contracts
28 | Signature and Unit
29 | Unsafe Libraries
30 | Drawing Conveniences
31 | Platform Dependencies
| Bibliography
| Index

► | 6 | color%

6.1 | Equality

On this page:

make-object
red
green
blue
alpha
set
copy-from
is-immutable?
ok?
6.1`` Equality

top contents ← prev up next →

class color% : class?
superclass: object%

A color is an object representing a red-green-blue (RGB) combination of primary colors plus an “alpha” for opacity. Each red, green, or blue component of the color is an exact integer in the range 0 to 255, inclusive, and the alpha value is a real number between 0 and 1, inclusive. For example, (0, 0, 0, 1.0) is solid black, (255, 255, 255, 1.0) is solid white, (255, 0, 0, 1.0) is solid red, and (255, 0, 0, 0.5) is translucent red.

See color-database<%> for information about obtaining a color object using a color name, and see also make-color.

> constructor (make-object color%) → (is-a?/c color%)
> (make-object color% red green blue [alpha]) → (is-a?/c color%)
> red : byte?
> green : byte?
> blue : byte?
> alpha : (real-in 0 1) = 1.0
> (make-object color% color-name-or-obj) → (is-a?/c color%)
> color-name-or-obj : (or/c string? (is-a?/c color%))

Creates a new color.

If three or four arguments are supplied to the constructor, the color is created with those RGB and alpha values.

If a single color% object is supplied, the color is created with the same RGB and alpha values as the given color.

If a string is supplied, then it is passed to the color-database<%>’s find-color method to find a color (signaling an error if the color is not in the color-database<%>’s get-names method’s result).

If no arguments are supplied, the new color is black.

> method (send a-color red) → byte?

Returns the red component of the color.

> method (send a-color green) → byte?

Returns the green component of the color.

> method (send a-color blue) → byte?

Returns the blue component of the color.

> method (send a-color alpha) → (real-in 0 1)

Returns the alpha component (i.e., opacity) of the color.

> method (send a-color set red green blue [alpha]) → void?
> red : byte?
> green : byte?
> blue : byte?
> alpha : (real-in 0 1) = 1.0

Sets the four (red, green, blue, and alpha) component values of the color.

> method (send a-color copy-from src) → (is-a?/c color%)
> src : (is-a?/c color%)

Copies the RGB values of another color object to this one, returning this object as the result.

> method (send a-color is-immutable?) → boolean?

Returns #t if the color object is immutable.

See also make-color and find-color in color-database<%>.

> method (send a-color ok?) → #t

Returns #t to indicate that the color object is valid.

(Historically, the result could be #f, but color objects are now always valid.)

#### 6.1`` Equality🔗ℹ

We can compare instances of color% using equal?. Two color% instances are equal if the red, green, blue, and alpha values are equal. I.e., a mutable and an immutable color% instance are equal as long as their values are equal.

top contents ← prev up next →