[ prev | next | top ]

3. Basic PIC Concepts

Pictures are described procedurally, as collections of objects connected by motions. Normally, pic tries to string together objects left-to-right in the sequence they are described, joining them at visually natural points. Here is an example illustrating the flow of data in pic processing:

Image grohtml-29071.png

Figure 3-1: Flow of pic data

This was produced from the following pic program:

ellipse "document";
box "\fIgpic\fP(1)"
box width 1.2 "\fIgtbl\/\fP(1) or \fIgeqn\/\fP(1)" "(optional)" dashed;
box "\fIgtroff\/\fP(1)";
ellipse "PostScript"

This little program illustrates several pic basics. Firstly, we see how to invoke three object types; ellipses, arrows, and boxes. We see how to declare text lines to go within an object (and that text can have font changes in it). We see how to change the line style of an object from solid to dashed. And we see that a box can be made wider than its default size to accommodate more text (we’ll discuss this facility in detail in the next section).

We also get to see pic’s simple syntax. Statements are ended by newlines or semicolons. String quotes are required around all text arguments, whether or not they contain spaces. In general, the order of command arguments and modifiers like “width 1.2” or “dashed” doesn’t matter, except that the order of text arguments is significant.

Here are all but one of the basic pic objects at their default sizes:

Image grohtml-29072.png

Figure 3-2: Basic pic objects

The missing simple object type is a spline. There is also a way to collect objects into block composites which allows you to treat the whole group as a single object (resembling a box) for many purposes. We’ll describe both of these later on.

The box, ellipse, circle, and block composite objects are closed; lines, arrows, arcs and splines are open. This distinction will often be important in explaining command modifiers.

Figure 3-2 was produced by the following pic program, which introduces some more basic concepts:

box "box";
line "line" "";
arrow "arrow" "";
circle "circle";
ellipse "ellipse";
arc; down; move; "arc"

The first thing to notice is the move command, which moves a default distance (1/2 inch) in the current movement direction.

Secondly, see how we can also decorate lines and arrows with text. The line and arrow commands each take two arguments here, specifying text to go above and below the object. If you wonder why one argument would not do, contemplate the output of arrow "ow!":

Image grohtml-29073.png

Figure 3-3: Text centered on an arrow

When a command takes one text string, pic tries to place it at the object’s geometric center. As you add more strings, pic treats them as a vertical block to be centered. The program

line "1";
line "1" "2";
line "1" "2" "3";
line "1" "2" "3" "4";
line "1" "2" "3" "4" "5";

for example, gives you this:

Image grohtml-29074.png

Figure 3-4: Effects of multiple text arguments

The last line of Figure 3.2’s program, ‘arc; down; move; "arc"’, describing the captioned arc, introduces several new ideas. Firstly, we see how to change the direction in which objects are joined. Had we written arc; move; "arc", omitting down the caption would have been joined to the top of the arc, like this:

Image grohtml-29075.png

Figure 3-5: Result of arc; move;

This is because drawing an arc changes the default direction to the one its exit end points at. To reinforce this point, consider:

Image grohtml-29076.png

Figure 3-6: Result of arc cw; move;

All we’ve done differently here is specify “cw” for a clockwise arc (“ccw” specifies counter-clockwise direction). Observe how it changes the default direction to down, rather than up.

Another good way to see this via with the following program:

line; arc; arc cw; line

which yields:

Image grohtml-29077.png

Figure 3-7: Result of line; arc; arc cw; line

Notice that we did not have to specify “up” for the second arc to be joined to the end of the first.

Finally, observe that a string, alone, is treated as text to be surrounded by an invisible box of a size either specified by width and height attributes or by the defaults textwid and textht. Both are initially zero (because we don’t know the default font size).

[ prev | next | top ]