procedure TWindow: set turtle window procedure TInit: initialize turtle system procedure TReset: reset turtle system procedure THome: return turtle to home procedure TScale: turtle scaling procedure THeading: turtle heading procedure TRight: turn turtle right procedure TLeft: turn turtle left procedure TFace: face turtle procedure TX: turtle x coordinate procedure TY: turtle y coordinate procedure TDraw: draw with turtle procedure TSkip: skip with turtle procedure TGoto: go to with turtle procedure TDrawto: draw to with turtle procedure TSave: save turtle state procedure TRestore: restore turtle state procedure TRect: draw rectangle centered at turtle procedure TFRect: draw filled rectangle centered at turtle procedure TCircle: draw circle centered at turtle procedure TFCircle: draw filled circle centered at turtle procedure TPoly: draw polygon centered at turtle procedure TFPoly: draw filled polygon centered at turtle
link turtle
August 8, 2000; Gregg M. Townsend
Requires: Version 9 graphics
This file is in the public domain.
These procedures provide a "turtle graphics" interface to Icon.
With this approach, popularized by the Logo programming language,
all drawing is done by a "turtle" that carries a pen over a drawing
surface under program control.
TWindow(W) sets the turtle window.
TDraw(n) moves forward and draws.
TSkip(n) skips forward without drawing.
TDrawto(x, y) draws to the point (x,y).
TScale(n) sets or queries current scaling factor.
TRight(d) turns right d degrees.
TLeft(d) turns left d degrees.
THeading(a) sets or queries the heading.
TFace(x, y) sets or queries the heading.
TX(x) sets or queries the current x position.
TY(y) sets or queries the current y position.
TGoto(x, y, a) sets the location and optionally changes the heading.
THome() moves to the window center and turns to face upward.
TReset() clears the window and reinitializes.
TSave() saves the turtle state.
TRestore() restores the turtle state.
TRect(h, w) draws a rectangle centered at the turtle.
TCircle(d) draws a circle centered at the turtle.
TPoly(d, n) draws a polygon centered at the turtle.
TFRect(h, w) draws a filled rectangle centered at the turtle.
TFCircle(d) draws a filled circle centered at the turtle.
TFPoly(d, n) draws a filled polygon centered at the turtle.
____________________________________________________________
In this package there is a single turtle which is itself invisible;
it is known only by the marks it leaves on the window. It remembers
its location and heading between calls.
No explicit initialization is required. The turtle begins at the
center of the window with a heading of -90 degrees (that is, pointed
towards the top of the window).
The turtle draws on &window unless a different window is specified by
calling TWindow(). If no window is provided and &window is null,
a 500x500 window is opened and assigned to &window.
Distances are measured in pixels and are always multiplied by a
settable scaling factor, initially 1. Angles are measured in degrees;
absolute angles measure clockwise from the positive X axis.
____________________________________________________________
The procedures are as follows:
TDraw(n) -- move forward and draw
TSkip(n) -- skip forward without drawing
The turtle moves forward n units. n can be negative to move
backwards.
Default: n = 1
TDrawto(x, y) -- draw to the point (x,y)
The turtle turns and draws a line to the point (x,y).
The heading is also set as a consequence of this movement.
Default: center of window
TScale(n) -- set or query current scaling factor.
If n is supplied, the scaling factor applied to TDraw and TSkip
arguments is *multiplied* (not replaced) by n. The resulting
(multiplied or unaltered) scaling factor is returned.
The turtle's heading and location do not change.
TRight(d) -- turn right
TLeft(d) -- turn left
The turtle turns d degrees to the right or left of its current
heading. Its location does not change, and nothing is drawn.
The resulting heading is returned.
Default: d = 90
THeading(a) -- set or query heading
The turtle's heading (in degrees) is returned. If a is supplied,
the heading is first set to that value. The location does not
change.
TFace(x, y) -- set or query heading
The turtle turns to face directly towards the point (x,y).
If x and y are missing or the turtle is already at (x,y),
the heading does not change. The new heading is returned.
Default: center of window
TX(x) -- set or query current x position
TY(y) -- set or query current y position
The unscaled x- or y-coordinate of the turtle's current location
is returned. If an argument is supplied, the coordinate value
is first set, moving the turtle without drawing. The turtle's
heading does not change.
TGoto(x, y, a) -- set location and optionally change heading
The turtle moves to the point (x,y) without drawing.
The turtle's heading remains unaltered unless <a> is supplied,
in which case the turtle then turns to a heading of <a>.
Default: center of window
THome() -- move to home (center of window) and point North
The turtle moves to the center of the window without drawing
and the heading is set to -90 degrees. The scaling factor
remains unaltered.
TReset() -- clear window and reinitialize
The window is cleared, the turtle moves to the center of the
window without drawing, the heading is set to -90 degrees, the
scaling factor is reset to 1, and the TRestore() stack is
cleared. These actions restore the initial conditions.
TSave() -- save turtle state
TRestore() -- restore turtle state
TSave saves the current turtle window, location, heading, and
scale on an internal stack. TRestore pops the stack and sets
those values, or fails if the stack is empty.
TRect(h, w) -- draw a rectangle centered at the turtle
TCircle(d) -- draw a circle centered at the turtle
TPoly(d, n) -- draw an n-sided regular polygon centered at the turtle
These three procedures draw a figure centered at the turtle's
current location. The location and heading do not change.
The base of the figure, if any, is directly behind the turtle.
TRect(h, w) draws a rectangle of height h and width w.
"width" is the dimension perpendicular to the turtle's path.
Default: h = 1
w = h
TCircle(d) draws a circle of diameter d.
Default: d = 1
TPoly(d, n) draws an n-sided regular polygon whose circumscribed
circle would have a diameter of d.
Default: d = 1
n = 3
TFRect(h, w) -- draw a filled rectangle centered at the turtle
TFCircle(d) -- draw a filled circle centered at the turtle
TFPoly(d, n) -- draw an n-sided filled polygon centered at the turtle
These are like their counterparts above, but a solid figure is
drawn instead of just an outline.
TWindow(win) -- set turtle window
The turtle is moved to the given window, retaining its
coordinates and heading.
Default: win = &window
These procedures do not attempt to provide a complete graphics interface;
in particular, no control of color is provided. Missing functions can
be accomplished by calling the appropriate Icon routines.
Unlike most turtle graphics environments, there are no commands to
lift and drop the pen. Instead, use TSkip() to move without drawing,
or set WAttrib("drawop=noop") if you really need a global "pen up"
state.