Panel/Agent-Windows/OGP64/usr/share/doc/groff-1.24.1/html/pic-9.html
2026-06-06 18:46:40 -04:00

123 lines
4.5 KiB
HTML

<!-- Creator : groff version 1.24.1 -->
<!-- CreationDate: Mon Mar 16 21:28:01 2026 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>pic-9.html</title>
</head>
<hr>
[ <a href="pic-8.html">prev</a> | <a href="pic-10.html">next</a> | <a href="pic.html">top</a> ]
<hr>
<h2>9. Naming Objects
<a name="9. Naming Objects"></a>
</h2>
<p style="margin-top: 1em"><font color="#000000">The most
natural way to name locations in <b>pic</b> is relative to
objects. In order to do this, you have to be able to name
objects. The <b>pic</b> language has rich facilities for
this that try to emulate the syntax of English.</font></p>
<h3>9.1. Naming Objects By Order Of Drawing
<a name="9.1. Naming Objects By Order Of Drawing"></a>
</h3>
<p style="margin-top: 1em"><font color="#000000">The
simplest (and generally the most useful) way to name an
object is with a <b>last</b> clause. It needs to be followed
by an object type name; <b>box</b>, <b>circle</b>,
<b>ellipse</b>, <b>line</b>, <b>arrow</b>, <b>spline</b>,
<b>&quot;&quot;</b>, or <b>[]</b> (the last type refers to a
<i>composite object</i> which we&rsquo;ll discuss later).
So, for example, the <b>last circle</b> clause in the
program attached to Figure 9.1.3 refers to the last circle
drawn.</font></p>
<p style="margin-top: 1em"><font color="#000000">More
generally, objects of a given type are implicitly numbered
(starting from&nbsp;1). You can refer to (say) the third
ellipse in the current picture with <b>3rd ellipse</b>, or
to the first box as <b>1st box</b>, or to the fifth text
string (which isn&rsquo;t an attribute to another object) as
<b>5th &quot;&quot;</b>.</font></p>
<p style="margin-top: 1em"><font color="#000000">Objects
are also numbered backward by type from the last one. You
can say <b>2nd last box</b> to get the second-to-last box,
or <b>3rd last ellipse</b> to get the third-to-last
ellipse.</font></p>
<p style="margin-top: 1em"><font color="#000000">In places
where <i>n</i><b>th</b> is allowed,
<b>`</b><i>expr</i><b>'th</b> is also allowed. Note that
<b>'th</b> is a single token: no space is allowed between
the <b>'</b> and the <b>th</b>. For example,</font></p>
<p style="margin-left:37%; margin-top: 1em"><font color="#000000">for
i = 1 to 4 do { <br>
line from `i'th box.nw to `i+1'th box.se <br>
}</font></p>
<h3>9.2. Naming Objects With Labels
<a name="9.2. Naming Objects With Labels"></a>
</h3>
<p style="margin-top: 1em"><font color="#000000">You can
also specify an object by referring to a label. A label is a
word (which must begin with a capital letter) followed by a
colon; you declare it by placing it immediately before the
object drawing command. For example, the program</font></p>
<p style="margin-left:28%; margin-top: 1em"><font color="#000000">.PS
<br>
A: box &quot;first&quot; &quot;object&quot; <br>
move; <br>
B: ellipse &quot;second&quot; &quot;object&quot; <br>
move; <br>
arrow right at A .r; <br>
.PE</font></p>
<p style="margin-top: 1em"><font color="#000000">declares
labels <b>A</b> and <b>B</b> for its first and second
objects. Here&rsquo;s what that looks like:</font></p>
<p align="center" style="margin-top: 1em"><font color="#000000"><img src="img/pic-31.png" alt="Image img/pic-31.png"></font></p>
<p align="center" style="margin-top: 1em"><font color="#000000">Figure
9-1: Example of label use</font></p>
<p style="margin-top: 1em"><font color="#000000">The
<b>at</b> statement in the fourth line uses the label
<b>A</b> (the behavior of <b>at</b> is explained in the next
section). We&rsquo;ll see later on that labels are most
useful for referring to block composite objects.</font></p>
<p style="margin-top: 1em"><font color="#000000">Labels are
not constants but variables (you can view colon as a sort of
assignment). You can say something like <b>A: A + (1,0);</b>
and the effect is to reassign the label <b>A</b> to
designate a position one inch to the right of its old
value.</font></p>
<hr>
[ <a href="pic-8.html">prev</a> | <a href="pic-10.html">next</a> | <a href="pic.html">top</a> ]
<hr>