User Tools

Site Tools


plato:tutor:line_drawing_summary

Summary of Line-drawing Commands: -draw-, -gdraw-, -rdraw-

Recall that the -draw- statement has the form:

draw point1;point2;point3;etc.

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”:

draw 1518;1538;skip;1738;1718

Using “skip” in a -draw- statement means “skip to the next point without drawing a line.” This example is essentially equivalent to:

draw 1518;1538 draw 1738;1718

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:

at 1319 $$ affects "where" draw 1518;1538;skip;1738;where

is equivalent to:

at 1319 draw 1518;1538 draw 1738;1319

since during the -draw- statement “where” has the value 1319. On the other hand, the sequence:

at 1319 draw 1518;1538 draw 1738;where

is equivalent to:

at 1319 draw 1518;1538 draw 1738;1538

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:

at 1319 draw ;1542;1942

is equivalent to:

at 1319 draw where;1542;1942

and is also equivalent to:

at 1319 draw 1319;1542;1942

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:

draw 1512;1542;skip;100,200; 400,200;400,400; 100,400;100,200

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:

at 2215 draw wherex+25,wherey-75;wherex+200,wherey+150

(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:

rorigin 2215 rdraw 25,-75;200,150

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:

origin 400,400 do chin1 rorigin 400,300 do chin2 etc.

Or you might include the -rorigin- statement in the character subroutines:

do chin1(400,400) do chin2(400,300)

In this case each subroutine has a form like this:

unit chin1(a,b) rorigin a,b rdraw -75,30;75,30;etc.

Unlike -draw-, the -rdraw- command is affected by preceding -sizeand -rotate- commands. Your Chinese characters can be enlarged and rotated:

size 3,5 $$ 3 times the width, 5 times the height rotate 45 $$ rotated 45 degrees do chin1(400,400) do chin2(400,300)

(Another way to handle such things as Chinese characters is with -lineset-.) Figure 9-8 shows a design created with the following commands:

rorigin 250,250 do figure,a⇐0,360,15 * unit figure rotate a rdraw -50,0;50,0;0,200;-50,0

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:

"ABSOLUTE" "RELATIVE" unit halfcirc unit halfcirc at x,y rorigin x,y $$ sets rorigin and "rat 0,0" circle radius,0,180 rcircle radius,0,180 draw x-radius,y;x+radius,y rdraw -radius,y;radius,y

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.

The -window- Command

plato/tutor/line_drawing_summary.txt · Last modified: 2023/08/05 18:56 by Site Administrator