Summary of Line-drawing Commands: -draw-, -gdraw-, -rdraw-
Recall that the -draw- statement has the form:
Each point in a -draw- statement may be coarse-grid (such as “1215”) or fine-grid (such as “135,245”). Each point specification is set off by a semicolon in order to avoid ambiguities when mixing coarse-grid and fine-grid points, as in “draw 1525;1932;35,120;1525” (the first two points are given in coarse-grid; the third, in fine-grid; and the last point in coarse-grid coordinates).
A discontinuous line drawing can be made with a single -drawstatement by using the word “skip”:
Using “skip” in a -draw- statement means “skip to the next point without drawing a line.” This example is essentially equivalent to:
The only difference between these otherwise equivalent forms is related to the fact that the system variables “where”, “wherex”, and “wherey” are not brought up to date until the completion of the -draw- statement. The sequence:
is equivalent to:
since during the -draw- statement “where” has the value 1319. On the other hand, the sequence:
is equivalent to:
since upon completion of the first -draw- statement, the value of “where” is 1538. This difference between a single -draw- using “skip” and separate -draw- statements is sometimes useful in drawing figures relative to some point.
As mentioned earlier, starting with a semicolon implies a continued drawing from the present screen location. The sequence:
is equivalent to:
and is also equivalent to:
Sometimes you have more points for a -draw- than will fit on one line. A “continued” -draw- can be written, with the command blank on succeeding lines:
This will behave as though all the points had been listed on one line.
To summarize, the -draw- statement contains fine-grid or coarse-grid points separated by semicolons, “skip” can be used for a discontinuous drawing, “where” and the fine-grid “wherex” and “wherey” are brought up to date upon completion of the -draw-, and starting the tag with a semicolon has the special meaning of continuing a drawing from the present screen position.
The -gdraw- command is like the -draw- command except that points are relative to the graphing coordinate system established by -gorigin-, -axes-, (or -bounds-), -scalex-, and -scaley- (or logarithmic scales set up by -lscalex- and -1scaley-). Of particular value are the “skip” option and starting with a semicolon (for continuing a drawing). The use of “where”, “wherex”, and “where),” in a -gdraw- statement is normally not meaningful, since these system variables refer to the absolute screen coordinate system, not the graphing system. In the graphing coordinate system, there are only fine-grid, not coarse-grid points, so all points have the form “x,y”.
It is possible to use -draw- to draw something relative to the present screen position:
(Remember that “wherex” and “wherey” do not change until the completion of the -draw- statement.) There is an -rdraw- command (“r” for “relative”) which makes such drawings simpler. The example just shown can be written:
Each point of an -rdraw- is taken to be relative to an origin established with an -rorigin- command.
The -rdraw- command is particularly useful for applications such as writing the same Chinese characters at different places on the screen. For each character, make a subroutine involving one or more -rdraw- statements. The characters can be positioned with -rorigin- statements:
Or you might include the -rorigin- statement in the character subroutines:
In this case each subroutine has a form like this:
Unlike -draw-, the -rdraw- command is affected by preceding -sizeand -rotate- commands. Your Chinese characters can be enlarged and rotated:
(Another way to handle such things as Chinese characters is with -lineset-.) Figure 9-8 shows a design created with the following commands:
The -rotate- command affects -rdraw- even with “size 0”, even though -write- is not rotated in size 0. (The -write- statement is unaffected in order to facilitate normal text operations.) As far as -rdraw- is concerned, size 0 is equivalent to size 1. As far as -write- is concerned, size 0 means “write text at 180 characters per second, unrotated”, whereas size 1 means “write line-drawn text at 6 characters per second, rotated”.
Note that -rdraw- and -size- are essentially reciprocal to -gdraw- and -scalex-. In the case of -rdraw-, a drawing gets bigger when -sizespecifies a larger size. But, specifying a larger number in a -scalexcommand implies that the same number of screen dots (given by -axes-) will now correspond to larger (scaled) numbers in a -gdraw-. This means that a larger -scalex- implies a smaller -gdraw- figure. Note that -goriginaffects -gdraw- the same way that -rorigin- affects -rdraw-.
There is a complete set of “relative” commands for making displays relative to an origin specified by -rorigin-, and affected by -size- and -rotate-. Here is a summary:
ABSOLUTE at atnm draw box vector circle
RELATIVE (-size-) rorigin rat ratnm rd raw rbox rvector rcircle
GRAPHING (-scalex-,-scaley-) gorigin gat gatnm gdraw gbox gvector gcircle
Note that -rcircle- will draw an ellipse if the x- and y-sizes are different (as in “size 1,4”, for example).
The “halfcirc” subroutine of Chapter 4 could be conveniently rewritten using relative commands:
It is important to note that the relative specifications set by -rorigin-, -size-, and -rotate-, as well as the graphing specifications set by -gorigin-, -bounds-, -scalex- (or -lscalex-) and -scaley- (or -lscaley-) carry over from one main unit to another. If you would prefer to have these parameters set to some standard values at the beginning of each main unit, simply do the initializations in an -imain- unit. (Remember that the -imain- command allows you to specify a unit to be performed every time a new main unit is started.)
How do you decide which of the three sets of display commands to use? If you want to rotate a drawing, you must use relative commands, because the absolute and graphing commands are unaffected by the -rotate- command. If rotations are not involved, just use whichever commands seem most convenient at the moment. Absolute commands may be used quite often since they are the simplest and easiest to use. The graphing commands are certainly best for drawing graphs of functions, but they are also useful whenever it is convenient to think of your drawing in terms of numerical scale factors. Graphing commands are also needed if you use polar coordinates (invoked with the -polarcommand). Sometimes you may use all three sets simultaneously. For example, in one of this author's lessons, the most convenient way to produce the screen display was to give instructions at the bottom of the screen using absolute commands, draw figures scaled in centimeters using graphing commands, and superimpose a movable box on the (absolute) instructions by means of relative commands.