ńņš. 4 |

(Figure 3bb will be inserted here; too bad you canā™t see it now.)

It is sometimes desirable to avoid points of inļ¬‚ection, when d is positive, and

to require the curve to remain inside the triangle determined by its initial and

ļ¬nal directions. This can be achieved by using three dots instead of two when you

specify a curve: The program

for d = 0 step 10 until 120:

draw (0, 0){dir 60} . . . {dir ā’d}(6cm , 0); endfor

Chapter 3: Curves 19

generates the curves bounded

controls

DESCARTES

DĀØ rer

u

Tory

Da Vinci

Serlio

(Figure 3cc will be inserted here; too bad you canā™t see it now.)

GOUDY

which are the same as before except that inļ¬‚ection points do not occur for the small

values of d. The ā˜. . .ā™ speciļ¬cation keeps the curve āboundedā inside the triangle that

is deļ¬ned by the endpoints and directions; but it has no eļ¬ect when there is no such

triangle. More precisely, suppose that the curve goes from z0 to z1 ; if thereā™s a point z

such that the initial direction is from z0 to z and the ļ¬nal direction is from z to z1 ,

then the curve speciļ¬ed by ā˜. . .ā™ will stay entirely within the triangle whose corners are

z0 , z1 , and z. But if thereā™s no such triangle (e.g., if d < 0 or d > 120 in our example

program), both ā˜. . .ā™ and ā˜. .ā™ will produce the same curves.

In this chapter we have seen lots of diļ¬erent ways to get

to draw curves. And thereā™s one more way, which subsumes all of the others.

If changes to tensions, curls, directions, and/or boundedness arenā™t enough to

produce the sort of curve that a person wants, itā™s always possible as a last

resort to specify all four of the points in the four-point method. For example,

the command

draw z4 . . controls z1 and z2 . . z6

will draw the following curve from z4 to z6 :

(Figure 3n will be inserted here; too bad you canā™t see it now.)

And so I think I have omitted nothing

that is necessary to an understanding of curved lines.

Ā“

ā” RENE DESCARTES, La GĀ“omĀ“trie (1637)

e e

Rules or substitutes for the artistā™s hand must necessarily be inadequate,

although, when set down by such men as

DĀØrer, Tory, Da Vinci, Serlio, and others,

u

they probably do establish canons of proportion and construction

which aļ¬ord a sound basis upon which to present new expressions.

ā” FREDERIC W. GOUDY, Typologia (1940)

(page 20)

4

Pens

Chapter 4: Pens 21

Our examples so far have involved straight lines or curved lines that look as pen

nib

if they were drawn by a felt-tip pen, where the nib of that pen was perfectly bean

round. A mathematical ālineā has no thickness, so itā™s invisible; but when we scaled

pickup

plot circular dots at each point of an inļ¬nitely thin line, we get a visible line draw

that has constant thickness. pencircle

pt

Lines of constant thickness have their uses, but also provides xscaled

several other kinds of scrivenerā™s tools, and we shall take a look at some of them yscaled

rotated

in this chapter. Weā™ll see not only that the sizes and shapes of pen nibs can be

varied, but also that characters can be built up in such a way that the outlines

of each stroke are precisely controlled.

First letā™s consider the simplest extensions of what we have seen before.

The letter ā˜ ā™ of Chapter 2 and the kidney-bean ā˜ ā™ of Chapter 3 were drawn

with circular pen nibs of diameter 0.4 pt, where ā˜ptā™ stands for a printerā™s point;*

0.4 pt is the standard thickness of a ruled line ā˜ ā™ drawn by TEX. Such a

penpoint can be speciļ¬ed by telling to

pickup pencircle scaled 0.4pt ;

will use the pen it has most recently picked up whenever it is asked

to ā˜drawā™ anything. A pencircle is a circular pen whose diameter is the width

of one pixel. Scaling it by 0.4pt will change it to the size that corresponds

to 0.4 pt in the output, because pt is the number of pixels in 1 pt. If the key

points (z1 , z2 , z3 , z4 , z5 , z6 ) of Chapters 2 and 3 have already been deļ¬ned, the

commands

pickup pencircle scaled 0.8pt ;

draw z5 . . z4 . . z1 . . z3 . . z6 . . cycle

will produce a bean shape twice as thick as before: ā˜ ā™ instead of ā˜ ā™.

More interesting eļ¬ects arise when we use non-circular pen nibs. For

example, the command

pickup pencircle xscaled 0.8pt yscaled 0.2pt

picks up a pen whose tip has the shape of an ellipse, 0.8 pt wide and 0.2 pt tall;

magniļ¬ed 10 times, it looks like this: ā˜ ā™. (The operation of āxscalingā mul-

tiplies x coordinates by a speciļ¬ed amount but leaves y coordinates unchanged,

and the operation of āyscalingā is similar.) Using such a pen, the ā˜ ā™ becomes

ā˜ ā™, and ā˜ ā™ becomes ā˜ ā™. Furthermore,

pickup pencircle xscaled 0.8pt yscaled 0.2pt rotated 30

takes that ellipse and rotates it 30ā—¦ counterclockwise, obtaining the nib ā˜ ā™; this

changes ā˜ ā™ into ā˜ ā™ and ā˜ ā™ into ā˜ ā™. An enlarged view of the bean shape shows

* 1 in = 2.54 cm = 72.27 pt exactly, as explained in The TEXbook.

22 Chapter 4: Pens

more clearly what is going on: draw

T

METAFONT logo

bounding box

box

h

w

(Figure 4a will be inserted here; too bad you canā™t see it now.)

The right-hand example was obtained by eliminating the clause ā˜yscaled 0.2pt ā™;

this makes the pen almost razor thin, only one pixel tall before rotation.

EXERCISE 4.1

Describe the pen shapes deļ¬ned by (a) pencircle xscaled 0.2pt yscaled 0.8pt ;

(b) pencircle scaled 0.8pt rotated 30; (c) pencircle xscaled .25 scaled 0.8pt .

EXERCISE 4.2

Weā™ve seen many examples of ā˜drawā™ used with two or more points. What do

you think will do if you ask it to perform the following commands?

draw z1 ; draw z2 ; draw z3 ; draw z4 ; draw z5 ; draw z6 .

Letā™s turn now to the design of a real letter that has already appeared

many times in this manual, namely the ā˜ ā™ of ā˜ ā™. All seven of the

distinct letters in ā˜ ā™ will be used to illustrate various ideas as we get

into the details of the language; we might as well start with ā˜ ā™, because it

occurs twice, and (especially) because itā™s the sim- (0,h) (w,h)

plest. An enlarged version of this letter is shown at

the right of this paragraph, including the locations

of its four key points (z1 , z2 , z3 , z4 ) and its bounding

box. Typesetting systems like TEX are based on the

assumption that each character ļ¬ts in a rectangular (Figure 4b will be inserted here;

too bad you canā™t see it now.)

box; we shall discuss boxes in detail later, but for

now we will be content simply to know that such

boundaries do exist.* Numbers h and w will have

been computed so that the corners of the box are at

positions (0, 0), (0, h), (w, 0), and (w, h) as shown. (0,0) (w,0)

Each of the letters in ā˜ ā™ is drawn

with a pen whose nib is an unrotated ellipse, 90% as tall as it is wide. In the

10-point size, which is used for the main text of this book, the pen is 2/3 pt wide,

* Strictly speaking, the bounding box doesnā™t actually have to āboundā the black pixels

of a character; for example, the ā˜ ā™ protrudes slightly below the baseline at point 4,

and italic letters frequently extend rather far to the right of their boxes. However,

TEX positions all characters by lumping boxes together as if they were pieces of metal

type that contain all of the ink.

Chapter 4: Pens 23

so it has been speciļ¬ed by the command o

overshoot

pickup pencircle scaled 2 pt yscaled 9 top

3 10 lft

rt

or something equivalent to this. bot

We shall assume that a special value ā˜oā™ has been computed so that the coordinates

M

bottom of the vertical stroke in ā˜ ā™ should descend exactly o pixels below the METAFONT logo

baseline; this is called the amount of āovershoot.ā Given h, w, and o, it is a

simple matter to deļ¬ne the four key points and to draw the ā˜ ā™:

top lft z1 = (0, h); top rt z2 = (w, h);

top z3 = (.5w, h); bot z4 = (.5w, ā’o);

draw z1 . . z2 ; draw z3 . . z4 .

Sometimes it is easier and/or clearer to deļ¬ne the x and y coordinates sepa-

rately. For example, the key points of the ā˜ ā™ could also be speciļ¬ed thus:

w ā’ x2 = x1 ;

lft x1 = 0; x3 = x4 = .5w;

bot y4 = ā’o;

top y1 = h; y1 = y2 = y3 .

The equation w ā’ x2 = x1 expresses the fact that x2 is just as far from the right edge

of the bounding box as x1 is from the left edge.

What exactly does ā˜topā™ mean in a equation? If the currently-

picked-up pen extends l pixels to the left of its center, r pixels to the right,

t pixels upward and b downward, then

bot z = z ā’ (0, b), lft z = z ā’ (l, 0),

top z = z + (0, t), rt z = z + (r, 0),

when z is a pair of coordinates. Butā”as the previous paragraph shows, if you study it

carefullyā”we also have

bot y = y ā’ b, lft x = x ā’ l,

top y = y + t, rt x = x + r,

when x and y are single values instead of coordinate pairs. You shouldnā™t apply ā˜topā™

or ā˜bot ā™ to x coordinates, nor ā˜lft ā™ or ā˜rt ā™ to y coordinates.

EXERCISE 4.3

True or false: top bot z = z, whenever z is a pair of coordinates.

EXERCISE 4.4

(0,h) (w,h)

An enlarged picture of ā™s

ā˜ ā™ shows that it has ļ¬ve key points. Assum-

ing that special values ss and ygap have been

precomputed and that the equations

x1 = ss = w ā’ x5 ; y3 ā’ y1 = ygap (Figure 4c will be inserted here; too bad you

canā™t see it now.)

have already been given, what further equa-

tions and ā˜drawā™ commands will complete the

speciļ¬cation of this letter? (The value of w

will be greater for ā˜ ā™ than it was for ā˜ ā™; it

stands for the pixel width of whatever char- (0,0) (w,0)

acter is currently being drawn.)

24 Chapter 4: Pens

ā™s ability to ā˜drawā™ allows it to produce character shapes that ļ¬ll

bean

are satisfactory for many applications, but the shapes are inherently limited by knife

the fact that the simulated pen nib must stay the same through an entire stroke. cycle

triangle

Human penpushers are able to get richer eļ¬ects by using diļ¬erent amounts of ā“

pressure and/or by rotating the pen as they draw. ..

polygonal path

We can obtain ļ¬ner control over the characters we produce if we specify

their outlines, instead of working only with key points that lie somewhere in the

middle. In fact, works internally with outlines, and the computer

ļ¬nds it much easier to ļ¬ll a region with solid black than to ļ¬gure out what pixels

are blackened by a moving pen. Thereā™s a ā˜ļ¬llā™ command that does region ļ¬lling;

for example, the solid bean shape

(Figure 4d will be inserted here; too bad you canā™t see it now.)

can be obtained from our six famous example points by giving the command

ļ¬ll z5 . . z4 . . z1 . . z3 . . z6 . . cycle.

The ļ¬lled region is essentially what would be cut out by an inļ¬nitely sharp knife

blade if it traced over the given curve while cutting a piece of thin ļ¬lm. A draw

command needs to add thickness to its curve, because the result would otherwise

be invisible; but a ļ¬ll command adds no thickness.

The curve in a ļ¬ll command must end with ā˜cycleā™, because an entire

region must be ļ¬lled. It wouldnā™t make sense to say, e.g., ā˜ļ¬ll z1 . . z2 ā™. The cycle

being ļ¬lled shouldnā™t cross itself, either; would have lots of trouble

trying to ļ¬gure out how to obey a command like ā˜ļ¬ll z1 . . z6 . . z3 . . z4 . . cycleā™.

EXERCISE 4.5

Chapter 3 discusses the curve z5 . . z4 . . z1 . . z3 . . z6 . . z5 , which isnā™t smooth

at z5 . Since this curve doesnā™t end with ā˜cycleā™, you canā™t use it in a ļ¬ll command. But

it does deļ¬ne a closed region. How can be instructed to ļ¬ll that region?

The black triangle ā˜ ā™ that appears in the statement of exercises in this

book was drawn with the command

ļ¬ll z1 - - z2 - - z3 - - cycle

after appropriate corner points z1 , z2 , and z3 had been speciļ¬ed. In this case the

outline of the region to be ļ¬lled was speciļ¬ed in terms of the symbol ā˜- -ā™ instead

of ā˜. .ā™; this is a convention we havenā™t discussed before. Each ā˜- -ā™ introduces

a straight line segment, which is independent of the rest of the path that it

belongs to; thus it is quite diļ¬erent from ā˜. .ā™, which speciļ¬es a possibly curved

Chapter 4: Pens 25

line segment that connects smoothly with neighboring points and lines of a path. equilateral

rotated

In this case ā˜- -ā™ was used so that the triangular region would have straight edges unļ¬ll

and sharp corners. We might say informally that ā˜. .ā™ means āConnect the points

with a nice curve,ā while ā˜- -ā™ means āConnect the points with a straight line.ā

The corner points z1 , z2 , and z3 were deļ¬ned care- (0,h) (w,h)

fully so that the triangle would be equilateral, i.e.,

so that all three of its sides would have the same length.

Since an equilateral triangle has 60ā—¦ angles, the following

equations did the job:

(Figure 4e will be inserted

x1 = x2 = w ā’ x3 = s; here; too bad you canā™t see

it now.)

y3 = .5h;

z1 ā’ z2 = (z3 ā’ z2 ) rotated 60.

Here w and h represent the characterā™s width and height,

and s is the distance of the triangle from the left and right

(0,0) (w,0)

edges of the type.

The ļ¬ll command has a companion called unļ¬ll, which changes pixels from

black to white inside a given region. For example, the solid bean shape on the

previous page can be changed to

(Figure 4f will be inserted here; too bad you canā™t see it now.)

if we say also ā˜unļ¬ll 1 [z4 , z2 ] . . 3 [z4 , z2 ] . . cycle; unļ¬ll 1 [z6 , z2 ] . . 3 [z6 , z2 ] . . cycleā™.

4 4 4 4

This example shows, incidentally, that converts a two-point speciļ¬cation

like ā˜z1 . . z2 . . cycleā™ into a more-or-less circular path, even though two points by

themselves deļ¬ne only a straight line.

EXERCISE 4.6

Let z0 be the point (.8[x1 , x2 ], .5[y1 , y4 ]), and introduce six new points by

letting zk = .2[zk , z0 ] for k = 1, 2, . . . , 6. Explain how to obtain the shape

(Figure 4g will be inserted here; too bad you canā™t see it now.)

in which the interior region is deļ¬ned by z1 . . . z6 instead of by z1 . . . z6 .

26 Chapter 4: Pens

The ability to ļ¬ll between outlines makes it possible to pretend that we broad-edge pens

angle of pen

have broad-edge pens that change in direction and pressure as they glide over ā“

the paper, if we consider the separate paths traced out by the penā™s left edge penpos

compass directions

and right edge. For example, the stroke

(Figure 4h will be inserted here; too bad you canā™t see it now.)

can be regarded as drawn by a pen that starts at the left, inclined at a 30ā—¦ angle;

as the pen moves, it turns gradually until its edge is strictly vertical by the time

it reaches the right end. The pen motion was horizontal at positions 2 and 3.

This stroke was actually obtained by the command

ļ¬ll z1l . . z2l {right } . . {right } z3l

- - z3r {left } . . {left } z2r . . z1r

- - cycle;

i.e., was asked to ļ¬ll a region bounded by a āleft pathā from z1l to

z2l to z3l , followed by a straight line to z3r , then a reversed āright pathā from

z3r to z2r to z1r , and ļ¬nally a straight line back to the starting point z1l .

Key positions of the āpenā are represented in this example by sets of

three points, like (z1l , z1 , z1r ), which stand for the penā™s left edge, its midpoint,

and its right edge. The midpoint doesnā™t actually occur in the speciļ¬cation of

the outline, but weā™ll see examples of its usefulness. The relationships between

such triples of points are established by a ā˜penpos ā™ command, which states the

breadth of the pen and its angle of inclination at a particular position. For

example, positions 1, 2, and 3 in the stroke above were established by saying

penpos1 (1.2pt , 30); penpos2 (1.0pt , 45); penpos3 (0.8pt , 90);

this made the pen 1.2 pt broad and tipped 30ā—¦ with respect to the horizontal at

position 1, etc. In general the idea is to specify ā˜penposk (b, d)ā™, where k is the

position number or position name, b is the breadth (in pixels), and d is the angle

(in degrees). Pen angles are measured counterclockwise from the horizontal.

Thus, an angle of 0 makes the right edge of the pen exactly b pixels to the right

of the left edge; an angle of 90 makes the right pen edge exactly b pixels above

the left; an angleā ā’90 makes it exactly b pixels below. An angle of 45 makes

of ā

the right edge b/ 2 pixels above and b/ 2 pixels to the right of the left edge;

ā ā

an angle of ā’45 makes it b/ 2 pixels below and b/ 2 to the right. When the

pen angle is between 90ā—¦ and 180ā—¦ , the ārightā edge actually lies to the left of

the āleftā edge. In terms of compass directions on a conventional map, an angle

of 0ā—¦ points due East, while 90ā—¦ points North and ā’90ā—¦ points South. The angle

corresponding to Southwest is ā’135ā—¦ , also known as +225ā—¦ .

EXERCISE 4.7

What angle corresponds to the direction North-Northwest?

Chapter 4: Pens 27

EXERCISE 4.8 rotated

penstroke

What are the pen angles at positions 1, 2, 3, and 4 in e

the circular shape shown here? [Hint: Each angle is a

multiple of 30ā—¦ . Note that z3r lies to the left of z3l .] (Figure 4i will be inserted

here; too bad you canā™t see

it now.)

EXERCISE 4.9

What are the coordinates of z1l and z1r after the com-

mand ā˜penpos1 (10, ā’90)ā™, if z1 = (25, 25)?

The statement ā˜penposk (b, d)ā™ is simply an abbreviation for two equations,

ā˜zk = 1 [zkl , zkr ]ā™ and ā˜zkr = zkl + (b, 0) rotated d ā™. You might want to use

2

other equations to deļ¬ne the relationship between zkl , zk , and zkr , instead of giving a

penpos command, if an alternative formulation turns out to be more convenient.

After ā˜penpos ā™ has speciļ¬ed the relations between three points, we still

donā™t know exactly where they are; we only know their positions relative to each

other. Another equation or two is needed in order to ļ¬x the horizontal and

vertical locations of each triple. For example, the three penpos commands that

led to the pen stroke on the previous page were accompanied by the equations

z1 = (0, 2pt ); z2 = (4pt , 0); x3 = 9pt ; y3l = y2r ;

ńņš. 4 |