Turtle Graphics

See all articles from Sinc-Link v8 n1
Author(s): Timothy Swenson
Publication: Sinc-Link
Pub Details: Sinc-Link v8 n1 (Volume 8, Issue 1)
Date: January/February 1990
Pages: 19

One of the most overlooked and unused capabilities of the QL is Turtle Graphics. Turtle Graphics is the basis of the language LOGO. Years ago LOGO was seen as the perfect language to start young children on. The heart of the language was the movement of a turtle cursor around the screen leaving a trail behind it. With simple loops one could get the turtle to draw a box or a five-point star.

Considering the past popularity of LOGO, I have yet to see any mention of Turtle Graphics on any QL related publication. It’s as if QL users are too advanced to use such simple commands.

I personaly think that using the already present Turtle Graphic commands, a workable LOGO can be implimented on the QL. Procedures can be used to add keywords to the language. Remember procedures can be called at the immediate level by entering their name.

Not knowing LOGO it would be hard for me to try this implementation myself, although if someone is willing to lend me a book on LOGO I’ll give it a try. I can still see using a LOGO type language to help children start programming.

Now it’s time for me to get off of my soapbox and spend some time explaining Turtle Graphics.

Turtle Graphics, as it was originaly concieved, can be pictured as a little robot (turtle) running around on the floor with a pen attached to it. The turtle can move forward, turn, lift the pen, and drop the pen (write). Now consider the screen as the floor and a dot as the turtle.

The commands that get the turtle to do things are quite simpe: PENDOWN and PENUP enable and disable the drawing of lines.

MOVE tells the turtle to move N units forward. TURN turns the turtle N degrees to the left. A negative N would turn it to the right. Both MOVE and TURN are relative. This means that they remeber the last place the turtle was and do the command from there.

TURNTO makes the turtle turn to a specific heading no matter what the last heading was. To move the turtle to a specific place use POINT. This sets the point and moves the turtle to that point. Turtle Graphics are based on the QL graphics system. Any graphic command affects the turtle. If you drew an ARC and then told the turtle to MOVE 5, the turtle would start at the end of the ARC.

This means that FILL may be used with turtle graphics. But be aware that the results may be a bit unexpected.

At the end of this article is a short program that demonstrates a use of Turtle Graphics. The program asks for a number of sides for a figure. The figure with 5 sides comes out to look like a 5-pointed star. All numbers entered must be odd. Give the program a try. Also try adding FILL statements and see what happens.

I hope I didn’t bore anyone with my ramblings.

100 CLS
110 INPUT "How many sides?"!sides
120 LET angle =
(360*(INT(sides/2)))/sides
130 CLS
140 POINT 10,50
150 PENDOWN
160 TURNTO 0
170 FOR x = 1 TO sides
180 MOVE 50
190 TURN -angle
200 NEXT x
210 BEEP 2000,10
220 PAUSE
230 GO TO 100

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.