| Graphics | Contents | Index | General Designs |
13 Drawing in Color
This chapter describes the :ink drawing option and the simpler values that
can be supplied for that option, such as colors. More complex values that have
a regular or irregular pattern in the ink are described in Chapter General Designs .
The drawing functions work by selecting a region of the drawing plane and painting it with color. The region to be painted is the intersection of the shape specified by the drawing function and the :clipping-region drawing option, which is then transformed by the :transformation drawing option. The :ink drawing option is a design that specifies a new arrangement of colors (and opacities) in this region of the medium's drawing plane. Any viewports or dataports attached to this drawing plane are updated accordingly. The :ink drawing option is never affected by the :transformation drawing option nor by the medium's transformation; this ensures that stipple patterns on adjacent sheets join seamlessly.
The color blending function is applied to the design's color and opacity and the drawing plane's color and opacity, returning a new color and opacity for the point.
The drawing plane's color and opacity at that point are set to the new color and opacity.
| design | [Protocol Class] |
A design can be characterized in several different ways:
All designs are either bounded or unbounded . Bounded designs are transparent everywhere beyond a certain distance from a certain point. Drawing a bounded design has no effect on the drawing plane outside that distance. Unbounded designs have points of non-zero opacity arbitrarily far from the origin. Drawing an unbounded design affects the entire drawing plane.
All designs are either uniform or non-uniform . Uniform designs have the same color and opacity at every point in the drawing plane. Uniform designs are always unbounded, unless they are completely transparent.
All designs are either solid or translucent . At each point a solid design is either completely opaque or completely transparent. A solid design can be opaque at some points and transparent at others. In translucent designs, at least one point has an opacity that is intermediate between completely opaque and transparent.
All designs are either colorless or colored . Drawing a colorless design uses a default color specified by the medium's foreground design. This is done by drawing with (compose-in +foreground-ink+ the-colorless-design) . See Chapter General Designs for the details of compose-in .
| designp | object | [Predicate] |
| color | [Protocol Class] |
A color can be specified by three real numbers between 0 and 1 (inclusive), giving the amounts of red, green, and blue. Three 0's mean black; three 1's mean white. The intensity-hue-saturation color model is also supported, but the red-green-blue color model is the primary model we will use in the specification.
| colorp | object | [Predicate] |
The following functions create colors. These functions produce objects that have equivalent effects; the only difference is in how the color components are specified. The resulting objects are indistinguishable when drawn. Whether these functions use the specified values exactly or approximate them because of limited color resolution is unspecified. Whether these functions create a new object or return an existing object with equivalent color component values is unspecified.
| make-rgb-color | red green blue | [Function] |
| make-ihs-color | intensity hue saturation | [Function] |
| make-gray-color | luminance | [Function] |
The following two functions comprise the color protocol. Both of them return the components of a color. All subclasses of color must implement methods for these generic functions.
| color-rgb | color | [Generic function] |
| color-ihs | color | [Generic function] |
13.3.1 Standard Color Names and Constants
Table 13.1 lists the commonly provided color names that can be
looked up with find-named-color . Application programs can define other
colors; these are provided because they are commonly used in the X Windows
community, not because there is anything special about these particular colors.
This table is a subset of the color listed in the file
/X11/R4/mit/rgb/rgb.txt , from the X11 R4 distribution.
| alice-blue | antique-white | aquamarine | |||
| azure | beige | bisque | |||
| black | blanched-almond | blue | |||
| blue-violet | brown | burlywood | |||
| cadet-blue | chartreuse | chocolate | |||
| coral | cornflower-blue | cornsilk | |||
| cyan | dark-goldenrod | dark-green | |||
| dark-khaki | dark-olive-green | dark-orange | |||
| dark-orchid | dark-salmon | dark-sea-green | |||
| dark-slate-blue | dark-slate-gray | dark-turquoise | |||
| dark-violet | deep-pink | deep-sky-blue | |||
| dim-gray | dodger-blue | firebrick | |||
| floral-white | forest-green | gainsboro | |||
| ghost-white | gold | goldenrod | |||
| gray | green | green-yellow | |||
| honeydew | hot-pink | indian-red | |||
| ivory | khaki | lavender | |||
| lavender-blush | lawn-green | lemon-chiffon | |||
| light-blue | light-coral | light-cyan | |||
| light-goldenrod | light-goldenrod-yellow | light-gray | |||
| light-pink | light-salmon | light-sea-green | |||
| light-sky-blue | light-slate-blue | light-slate-gray | |||
| light-steel-blue | light-yellow | lime-green | |||
| linen | magenta | maroon | |||
| medium-aquamarine | medium-blue | medium-orchid | |||
| medium-purple | medium-sea-green | medium-slate-blue | |||
| medium-spring-green | medium-turquoise | medium-violet-red | |||
| midnight-blue | mint-cream | misty-rose | |||
| moccasin | navajo-white | navy-blue | |||
| old-lace | olive-drab | orange | |||
| orange-red | orchid | pale-goldenrod | |||
| pale-green | pale-turquoise | pale-violet-red | |||
| papaya-whip | peach-puff | peru | |||
| pink | plum | powder-blue | |||
| purple | red | rosy-brown | |||
| royal-blue | saddle-brown | salmon | |||
| sandy-brown | sea-green | seashell | |||
| sienna | sky-blue | slate-blue | |||
| slate-gray | snow | spring-green | |||
| steel-blue | tan | thistle | |||
| tomato | turquoise | violet | |||
| violet-red | wheat | white | |||
| white-smoke | yellow | yellow-green | |||
| +red+ | [Constant] |
| +green+ | [Constant] |
| +blue+ | [Constant] |
| +cyan+ | [Constant] |
| +magenta+ | [Constant] |
| +yellow+ | [Constant] |
| +black+ | [Constant] |
| +white+ | [Constant] |
| make-contrasting-inks | n &optional k | [Function] |
If k is supplied, it must be an integer between 0 and n -1 (inclusive), in which case make-contrasting-inks returns the k 'th design rather than returning a vector of designs.
If the implementation does not have n different contrasting inks, make-contrasting-inks signals an error. This will not happen unless n is greater than eight.
The rendering of the design may be a color or a stippled pattern, depending on whether the output medium supports color.
| contrasting-inks-limit | port | [Generic function] |
| opacity | [Protocol Class] |
Opacity controls how graphical output covers previous output. Opacity can vary from totally opaque to totally transparent. Intermediate opacity values result in color blending so that the earlier picture shows through what is drawn on top of it.
An opacity may be specified by a real number between 0 and 1 (inclusive). 0 is completely transparent, 1 is completely opaque, fractions are translucent. The opacity of a design is the degree to which it hides the previous contents of the drawing plane when it is drawn.
The fully transparent and fully opaque opacity levels (that is, opacities 0 and 1) must always be supported, but a valid CLIM implementation might only support a handful of opacity levels in between (including none). A valid CLIM implementation might implement color blending and unsaturated colors by stippling, although it is preferred, when possible, for a viewport to display a uniform color as a uniform color rather than as a perceptible stipple.
| opacityp | object | [Predicate] |
The following function returns an opacity:
| make-opacity | value | [Function] |
| +transparent-ink+ | [Constant] |
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] |
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 General Designs 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 | |||||
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 either because the implementation has limited opacity resolution or because the implementation can compute a different color blending function much more quickly.
If a medium's background design is not completely opaque at all points, the consequences are unspecified. Consequently, a drawing plane is always opaque and drawing can use simplified color blending that assumes o2 = 1 and o3 = 1. However, compose-over must handle a non-opaque background correctly.
Note that these (r,g,b,o) quadruples of real numbers between 0 and 1 are mathematical and an implementation need not store information in this form. Most implementations are expected to use a different representation.
13.6 Indirect Inks
Drawing with an indirect ink is the same as drawing another design
named directly. For example, +foreground-ink+ is a design that draws the
medium's foreground design and is the default value of the :ink drawing
option. Indirect inks exist for the benefit of output recording. For example,
one can draw with +foreground-ink+ , change to a different
medium-foreground , and replay the output record; the replayed output will
come out in the new color.
You can change the foreground or background design of a medium at any time. This changes the contents of the medium's drawing plane. The effect is as if everything on the drawing plane is erased, the background design is drawn onto the drawing plane, and then everything that was ever drawn (provided it was saved in the output history) is drawn over again, using the medium's new foreground and background.
If an infinite recursion is created using an indirect ink, an error is signalled when the recursion is created, when the design is used for drawing, or both.
Two indirect inks are defined, but no advertised way is provided to create more of them.
| +foreground-ink+ | [Constant] |
| +background-ink+ | [Constant] |
| make-flipping-ink | design1 design2 | [Function] |
The opacity of a flipping ink is zero at points where the opacity of either design1 or design2 is zero. Otherwise the opacity of a flipping ink is 1. If design1 or design2 is translucent, the consequences are unspecified. If compose-in or compose-out is used to make a flipping ink translucent, the consequences are unspecified.
If design1 and design2 are equivalent, the result can be +nowhere+ .
In Release 2, make-flipping-ink might require design1 and design2 to be colors.
| +flipping-ink+ | [Constant] |
13.8 Examples of Simple Drawing Effects
Drawing in the foreground color.
Use the default, or specify :ink +foreground-ink+ .
Erasing.
Specify :ink +background-ink+ .
Drawing in color.
Specify :ink +green+ , :ink (make-rgb-color 0.6 0.0 0.4) , and so forth.
Drawing an opaque gray.
Specify :ink (make-gray-color 0.25) to draw in a shade of gray independent
of the window's foreground color. On a non-color, non-grayscale display this
will generally turn into a stipple.
| Graphics | Contents | Index | General Designs |