?? unx25.htm
字號:
<P>pic comes to your rescue with a solution. It understands Cartesian coordinates, as shown in Figure 25.3.
<BR></P>
<P>
<BR><B><A HREF="25unx15.gif">Figure 25.3. </B><B><I>x,y</I></B><B> coordinates.</A></B>
<BR></P>
<P>Again, the unit is inches. The important thing to remember is that your first object starts at 0,0. In other words, the coordinates are relative. There is no specific location on a page or in a drawing that is always 0,0. It depends on where you start.
<BR></P>
<P>Cartesian coordinates enable you to specify the two boxes shown in Figure 25.1 as
<BR></P>
<PRE>.PS
box at 0,0 "Box 1"
box at 0,-1 "Box 2"
.PE</PRE>
<P>You'll probably find this easier.
<BR></P>
<P>pic also has an invis command. At first glance, it doesn't seem very useful. How often do you expect to draw a page full of invisible boxes? The real advantage of invis is in placing text. Consider Figure 25.4.
<BR></P>
<P>
<BR><B><A HREF="25unx16.gif">Figure 25.4. Using invisible lines.</A></B>
<BR></P>
<P>Placing those pesky dots could be a problem. Using invis, though, makes it easy. The code that produces Figure 25.4 is
<BR></P>
<PRE>.PS
box; move; box
line invis .75 "\s12 . . . \s0"
box
.PE</PRE>
<P>There are other uses for invis. You can use it, for example, to define a large area in which you will be drawing several smaller objects and to provide compass points outside a smaller object.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I11" NAME="I11">
<FONT SIZE=4><B>Additional Shapes and Functions</B>
<BR></FONT></A></CENTER></H3>
<P>pic includes two more shapes in addition to the ones you've already seen. They are the arc and the spline.
<BR></P>
<P>To pic, an arc is a quarter of a circle. You can use the arc command to draw a circle, as in
<BR></P>
<PRE>.PS
arc; arc; arc; arc
.PE</PRE>
<P>A more sensible use of arc is to draw a rectangle with rounded corners. For example,
<BR></P>
<PRE>.PS
line left; arc; line down; arc
line right; arc; line up; arc
.PE</PRE>
<P>To make a spiral like the one shown in Figure 25.5, combine a series of arcs. For example,
<BR></P>
<PRE>.PS
arc rad .04
arc rad .08
arc rad .12
arc rad .16
arc rad .20
arc rad .24
arc rad .28
arc rad .32
arc rad .36
arc rad .40
arc rad .44
arc rad .48
.PE</PRE>
<P>produces the following:
<BR></P>
<P>
<BR><B><A HREF="25unx20.gif">Figure 25.5. A spiral made of arcs.</A></B>
<BR></P>
<P>pic also recognizes trigonometric and other mathematical functions:
<BR></P>
<TABLE BORDER>
<TR>
<TD>
<P>atan2 </P>
<TD>
<P>(e<SUB>1</SUB>, e<SUB>2</SUB>)</P>
<TD>
<P>the arctangent of e<SUB>1</SUB>, e<SUB>2</SUB></P>
<TR>
<TD>
<P>cos </P>
<TD>
<P><BR></P>
<TD>
<P>cosine of e (e must be in radians)</P>
<TR>
<TD>
<P>exp </P>
<TD>
<P><BR></P>
<TD>
<P>10<SUP>e</SUP></P>
<TR>
<TD>
<P>int </P>
<TD>
<P><BR></P>
<TD>
<P>integer part (by truncation)</P>
<TR>
<TD>
<P>log </P>
<TD>
<P><BR></P>
<TD>
<P>logarithm base 10 of e</P>
<TR>
<TD>
<P>max </P>
<TD>
<P>(e<SUB>1</SUB>, e<SUB>2</SUB>)</P>
<TD>
<P>maximum of e<SUB>1</SUB> and e<SUB>2</SUB></P>
<TR>
<TD>
<P>min </P>
<TD>
<P>(e<SUB>1</SUB>, e<SUB>2</SUB>)</P>
<TD>
<P>minimum of e<SUB>1</SUB> and e<SUB>2</SUB></P>
<TR>
<TD>
<P>rand </P>
<TD>
<P>(n)</P>
<TD>
<P>random number between 1 and n</P>
<TR>
<TD>
<P>sin </P>
<TD>
<P><BR></P>
<TD>
<P>sine of e (e must be in radians)</P>
<TR>
<TD>
<P>sqrt </P>
<TD>
<P><BR></P>
<TD>
<P>square root of e</P></TABLE>
<P>These functions must be followed by an expression in parentheses. In the case of atan2, max, and min, two expressions must follow. rand is followed by empty parentheses and produces a random number between 0 and 1.
<BR></P>
<P>Lines and shapes don't have to be solid. You can draw dotted and dashed objects. Consider the following code.
<BR></P>
<PRE>.PS
B1: box
move to B1.n up .05 right .05
B2: box dashed
move to B2.n up .05 right .05
B3: box dotted
.PE</PRE>
<H3 ALIGN="CENTER">
<CENTER><A ID="I12" NAME="I12">
<FONT SIZE=4><B>Controlling Size</B>
<BR></FONT></A></CENTER></H3>
<P>pic variables include several that specify the default size of pic objects. Table 25.1 lists these variables and their default values.
<BR></P>
<UL>
<LH><B>Table 25.1. Default values of </B><B>pic</B><B> variables.</B>
<BR></LH></UL>
<TABLE BORDER>
<TR>
<TD>
<PRE><I>Variable</I>
<BR></PRE>
<TD>
<PRE><I>Default Value</I>
<BR></PRE>
<TD>
<PRE><I>Variable</I>
<BR></PRE>
<TD>
<PRE><I>Default Value</I>
<BR></PRE>
<TR>
<TD>
<P>arcrad</P>
<TD>
<P>.25i</P>
<TD>
<P>ellipsewid</P>
<TD>
<P> .75i</P>
<TR>
<TD>
<P>arrowhead</P>
<TD>
<P> 2i</P>
<TD>
<P>lineht</P>
<TD>
<P> .5i</P>
<TR>
<TD>
<P>arrowht</P>
<TD>
<P> .1i</P>
<TD>
<P>linewid</P>
<TD>
<P> .75i</P>
<TR>
<TD>
<P>arrowwid</P>
<TD>
<P>.05i</P>
<TD>
<P>moveht</P>
<TD>
<P> .5i</P>
<TR>
<TD>
<P>boxht</P>
<TD>
<P> .5i</P>
<TD>
<P>movewid</P>
<TD>
<P> .75i</P>
<TR>
<TD>
<P>boxwid</P>
<TD>
<P>.75i</P>
<TD>
<P>scale</P>
<TD>
<P> 1i</P>
<TR>
<TD>
<P>circlerad</P>
<TD>
<P>.25i</P>
<TD>
<P>textht</P>
<TD>
<P> 0i</P>
<TR>
<TD>
<P>dashwid</P>
<TD>
<P> .5i</P>
<TD>
<P>textwid</P>
<TD>
<P> 0i</P>
<TR>
<TD>
<P>ellipseht</P>
<TD>
<P> .5i</P>
<TD>
<P><BR></P>
<TD>
<P><BR></P></TABLE>
<P>arrowwid and arriowht refer to the arrowhead. The arrowhead variable specifies the fill style of the arrowhead.
<BR></P>
<P>It's easy to change the value of a variable. For example,
<BR></P>
<PRE>boxht = .75; boxwid = .5</PRE>
<P>Remember: The default unit for pic is inches.
<BR></P>
<P>There are other ways of controlling the size of a picture. You can specify a height or a width—or both—on the .PS line. Usually it's better to specify only the width. If you specify both dimensions, your picture may be distorted.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> For some reason, you must specify the width first. For example, .PS 2 4 produces a picture 2 inches wide and 4 inches long. This is the opposite of the order in which you specify the dimensions of a
box or ellipse. The width and height you specify refer to the whole picture.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>You can also set the variable scale. By default, scale is set at 100 or 1, depending on your version of pic. (You can test this by scaling a drawing to 1.5. If you get an error message or a garbled result, use 150.) All the dimensions in a pic drawing
are divided by the scaling factor. Therefore, if the scale is normally 1 and you set it to 4, your 1-inch lines will be a quarter-inch long. For example,
<BR></P>
<PRE>.PS
scale = 2
box ht 2i wid 2i
.PE</PRE>
<P>This code produces a box scaled down to half the size of its specifications, that is, a 1- inch square.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="caution.gif" WIDTH = 37 HEIGHT = 35><B>CAUTION: </B>Text is not scaled. If your text needs resizing, you must do it with \s, and it's usually a matter of trial and error to find out what will fit in your scaled figure.
<BR></NOTE>
<HR ALIGN=CENTER>
<H3 ALIGN="CENTER">
<CENTER><A ID="I13" NAME="I13">
<FONT SIZE=4><B>Object Blocks</B>
<BR></FONT></A></CENTER></H3>
<P>You can define any sequence of objects or moves as a block, which you can manipulate almost as if it were a simple box. You need to name the block. The name must begin with an uppercase letter. Although pic places no specific restrictions on the length
of the name, shorter is better.
<BR></P>
<P>Object blocks are useful when you are placing text.
<BR></P>
<P>You can also position an object block easily, as in
<BR></P>
<PRE>.PS
C1: circle rad .125
Spiral [
arc rad .04
arc rad .08
arc rad .12
arc rad .16
arc rad .20
arc rad .24
arc rad .28
arc rad .32
arc rad .36
arc rad .40
arc rad .44
arc rad .48
] with .s at C1.n
.PE</PRE>
<H3 ALIGN="CENTER">
<CENTER><A ID="I14" NAME="I14">
<FONT SIZE=4><B>Macros and Variables</B>
<BR></FONT></A></CENTER></H3>
<P>If you want to reuse an object, you can put it in a file by itself and use the copy function:
<BR></P>
<PRE>.PS
<pic code>
copy filename
<pic code>
.PE</PRE>
<P>You can also define a pic macro. Don't confuse pic macros with troff macros. In the broadest sense, a macro is a short way of referring to a complex process. In other words, a pic macro is just a collection of pic commands that have been given a name.
<BR></P>
<P>Unlike object blocks, which merely give you a convenient way of referring to positions in and around the object, macros can be used to draw objects. The first three lines of the following code sequence enable you to draw the defined object by invoking
its name, as shown in the last line.
<BR></P>
<PRE>.PS
define SQ %
box ht .5 wid .5
%
SQ; move; SQ
.PE</PRE>
<P>This code produces
<BR></P>
<P><B><IMG SRC="25unx21.gif"></B></P>
<P>To create a macro, use the word define followed by a name for your macro and a delimeter. Next come all your pic instructions and finally, another delimeter. In the first example, I used % for delimeters. In the second example, I used curly braces.
There is no default. The choice is yours.
<BR></P>
<P>Macros can have up to nine arguments, specified $1 through $9. For example, you can define a square and supply the dimensions as arguments when you invoke the macro, as shown in the first three lines of the following code. The last line produces the 1/2
inches square shown in Figure 25.6.
<BR></P>
<PRE>.PS
define SQ }
box ht $1 wid $1 "$2"
{
SQ(.5, square)
.PE</PRE>
<P>produces
<BR></P>
<P>
<BR><B><A HREF="25unx22.gif">Figure 25.6. Squares Created with a Macro</A></B>
<BR></P>
<P>Macro definitions require delimiters. As you can see, though, the choice is up to you. Percent signs (%) are usual choices. When you invoke the macro, the arguments go in parentheses.
<BR></P>
<P>Macro definitions persist throughout a file. If you ever have to get rid of a macro, use undef SQ—or whatever you've named your macro.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I15" NAME="I15">
<FONT SIZE=4><B>Debugging</B>
<BR></FONT></A></CENTER></H3>
<P>When you're dealing with pic, you aren't troubleshooting—you're debugging. It's much easier to do this as you code. Draw the first element of your picture. Before you print it, send the file through pic to see whether any error messages are
generated. If your file contains only pic, you can do this:
<BR></P>
<PRE>pic filename</PRE>
<P>If your file contains text, just use your normal troff command line. However, instead of sending the file to a printer, redirect your output to /dev/null. See Chapter 28, "Tools for Writers," for more information on directing output to
/dev/null.
<BR></P>
<P>pic tries to help you pinpoint your errors with messages similar to the following:
<BR></P>
<PRE>pic: syntax error near line 26
context is
>>> linr <<< left 1i</PRE>
<P>Occasionally, pic tells you that it has reduced the size of your picture. This is almost always because you've made a mistake. Most often, you've left out a decimal point, and pic is trying to fit a line 1625 inches long—you meant 1.625
inches—on an 8.5-inch page. When this happens, your picture naturally is mangled out of all recognition.
<BR></P>
<P>Usually, your debugging involves the placement of objects and the placement or size of text.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I16" NAME="I16">
<FONT SIZE=4><B><I>pic</I></B><B> Tips and Tricks</B>
<BR></FONT></A></CENTER></H3>
<P>If you can't get an object placed correctly by moving down and left (or up and right) from an object, try referring to both objects by their centers, as in box.c.
<BR></P>
<P>If your drawing involves a number of objects and placement is crucial, use x,y coordinates.
<BR></P>
<P>If you're having trouble placing text, remember over and under.
<BR></P>
<P>Using a box invis or a line invis to place your text usually works well.
<BR></P>
<P>Make yourself a library of pic drawings so that you don't have to keep reinventing the spiral.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I17" NAME="I17">
<FONT SIZE=4><B>Summary</B>
<BR></FONT></A></CENTER></H3>
<P>pic is a troff preprocessor for drawing lines, arrows, boxes, circles, ellipses, arcs, and splines. Output tends to vary from system to system, so be prepared to spend some time debugging. pic is well worth the trouble if you frequently include simple
graphics in text files. It is especially useful for organization charts, flow charts, state diagrams, and the like.
<BR></P>
<P><A HREF="unx24.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index.htm"><IMG SRC="blutoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="unx26.htm"><IMG SRC="blunext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<A HREF="index.htm"><IMG SRC="bluprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Home"></A>
</P></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -