Draws turtle-style line patterns from the centre of the screen. It asks for the number of repeats, the angle to turn right, the number of steps forward, an increment added to the turning angle after each move, and whether to clear the screen first. A zero increment gives regular polygons and stars, and a non-zero increment curls the path into spirals. After each pattern it asks again, so new figures can be drawn over the old ones. The program was saved as “turt 2.”
Program Analysis
Program Structure
Line 20 defines FN R to convert degrees to radians. Lines 40–65 collect the settings. If the screen is cleared, PLOT 127,87 puts the drawing position at the centre. The loop at 80–130 adds RIGHT to the heading, works out the move with SIN and COS, draws it with a relative DRAW, and then adds INCSTEP to RIGHT. Line 140 returns to the prompts.
Potential Issues
ANGLEis only zeroed at line 30, and the pen is not moved back to the centre unless the screen is cleared. Each new pattern therefore starts from the previous heading and end point.- No bounds check is made, so a pattern that runs off the screen stops with an “Integer out of range” error.
Source Code
10 REM TINY TURTLE
20 DEF FN R(X)=X*PI/180
30 LET ANGLE=0
40 INPUT "NO. OF REPEATS? ";REPEAT
50 INPUT "ANGLE TURN TO RIGHT? ";RIGHT
60 INPUT "STEPS FORWARD? ";FORWARD
62 INPUT "STEP INCREMENT ";INCSTEP
65 INPUT "CLEAN BEFORE DRAWING (Y/N)? ";A$
70 IF A$="Y" OR A$="y" THEN CLS : PLOT 127,87
80 FOR A=1 TO REPEAT
90 LET ANGLE=ANGLE+RIGHT
100 LET ACROSS=SIN (FN R(ANGLE))*FORWARD
110 LET DOWN=COS (FN R(ANGLE))*FORWARD
120 DRAW ACROSS,DOWN
125 LET RIGHT=RIGHT+INCSTEP
130 NEXT A
140 GO TO 40Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
