Page 118 Table of Contents Index Page 120
Chapters
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
A, B, C, D, E



CHAPTER 13. DRAWING IN COLOR

=> make-opacity value [Function]
Returns a member of class opacity whose opacity is value, which is a real number in the range
from 0 to 1 (inclusive), where 0 is fully transparent and 1 is fully opaque.

The following function returns the sole component of an opacity. This is the only function in the
opacity protocol. All subclasses of opacity must implement methods for this generic function.

=> opacity-value opacity [Generic Function]
Returns the opacity value of the opacity opacity, which is a real number in the range from 0 to
1 (inclusive).

13.5 Color Blending

Drawing a design that is not completely opaque at all points allows the previous contents of the
drawing plane to show through. The simplest case is drawing a solid design: where the design is
opaque, it replaces the previous contents of the drawing plane; where the design is transparent,
it leaves the drawing plane unchanged. In the more general case of drawing a translucent design,
the resulting color is a blend of the design's color and the previous color of the drawing plane.
For purposes of color blending, the drawn design is called the foreground and the drawing plane
is called the background.

The function compose-over performs a similar operation: it combines two designs to produce
a design, rather than combining a design and the contents of the drawing plane to produce
the new contents of the drawing plane. For purposes of color blending, the first argument to
compose-over is called the foreground and the second argument is called the background. See
Chapter 14 for the details of compose-over.

Color blending is defined by an ideal function F:(r1, g1, b1, o1, r2, g2, b2, o2) -> ( r3, g3, b3, o3) that
operates on the color and opacity at a single point. (r1, g1, b1, o1) are the foreground color and
opacity. (r2, g2, b2, o2) are the background color and opacity. (r3, g3, b3, o3) are the resulting
color and opacity. The color blending function F is conceptually applied at every point in the
drawing plane.

F performs linear interpolation on all four components:

o3 = o1 + (1 - o1) * o2
r3 = (o1 * r1 + (1 - o1) * o2 * r2) / o3
g3 = (o1 * g1 + (1 - o1) * o2 * g2) / o3
b3 = (o1 * b1 + (1 - o1) * o2 * b2) / o3

Note that if o3 is zero, these equations would divide zero by zero. In that case r3 , g3 , and b3 are
defined to be zero.

CLIM requires that F be implemented exactly if o1 is zero or one or if o2 is zero. If o1 is
zero, the result is the background. If o1 is one or o2 is zero, the result is the foreground. For
fractional opacity values, an implementation can deviate from the ideal color blending function


Page 118 Table of Contents Index Page 120
Chapters
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
A, B, C, D, E