--- title: "Tiny Turtle" id: 56322 type: "computer_media" slug: "tinyturtle" url: "http://localhost/computer_media/tinyturtle/" markdown_url: "http://localhost/computer_media/tinyturtle.md" published_at: "2024-08-04T10:50:00+00:00" modified_at: "2026-03-30T21:46:02+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/08/tinyturtle.gif" excerpt: "Draw spirals, polygons, and abstract patterns with this turtle-graphics engine driven entirely by angle, step length, and an optional growth increment." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Tim Hartnell" slug: "tim-hartnell" taxonomy: "indiv" url: "http://localhost/indiv/tim-hartnell/" genre: - name: "Entertainment" slug: "entertainment" taxonomy: "genre" url: "http://localhost/type/entertainment/" media_contents: - id: 56277 title: "Timex Sinclair Public Domain Library Tape 2001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-2001/" media_type: "Program" programmers: - name: "Tim Hartnell" slug: "tim-hartnell" taxonomy: "indiv" url: "http://localhost/indiv/tim-hartnell/" download_url: "https://archive.org/download/timex-sinclair-software-archive/TinyTurtle%20%281986%29%28Hartnell%2C%20Tim%29%28TS2068%29%28UK%29%28Program%29.zip" spectrum_computing: "https://worldofspectrum.net/item/0023194/" mediadate: "1986" images: - url: "http://localhost/wp-content/uploads/2024/08/tinyturtle.gif" media_type_tags: "Entertainment" --- Tiny Turtle is a BASIC turtle-graphics program that draws repeated line segments using DRAW commands, with user-controlled parameters for repeat count, turning angle, step length, and a step increment that grows (or shrinks) the segment length each iteration. The degree-to-radian conversion is handled by a defined function at line 20 using DEF FN r(x)=x*PI/180, exploiting the built-in PI constant. A persistent angle accumulator (line 90) means successive runs without clearing will continue from where the previous drawing left off. The program loops back to line 40 after each drawing, allowing the user to layer multiple patterns on the same screen or clear between them. *** ## Program Analysis ### Program Structure The program is organised into three logical phases: initialisation (lines 1–30), user input collection (lines 40–65), and the drawing loop (lines 70–130), followed by an unconditional return to the input phase at line 140. This creates an infinite interactive loop that allows the user to build up layered drawings without restarting the program. 1. **Lines 1–20:** REMs and the degree-to-radian function definition. 2. **Line 30:** Initialises the cumulative angle to zero once at program start. 3. **Lines 40–65:** Collects five user parameters each cycle. 4. **Lines 70–130:** Optionally clears the screen, then runs the drawing loop. 5. **Line 140:** Loops back to input, preserving `angle` across iterations. ### Degree-to-Radian Conversion Line 20 defines `FN r(x)` as `x*PI/180`, converting degrees to radians for use with the trigonometric functions `SIN` and `COS`. This is a common BASIC idiom on the Spectrum, where all trig functions operate in radians but users typically think in degrees. Encapsulating the conversion in a `DEF FN` keeps lines 100 and 110 readable. ### Turtle-Graphics Mechanics Rather than tracking an absolute screen position, the program uses the Spectrum’s `DRAW` command with relative offsets. At each step, `across` and `down` are computed from the current cumulative `angle` using standard trigonometric projection: - `across = SIN(angle_rad) * forward` — horizontal component - `down = COS(angle_rad) * forward` — vertical component Note that the axes are swapped compared to conventional mathematics: SIN drives X and COS drives Y. This is intentional for a heading-based turtle model where angle 0 points upward. ### Cumulative Angle and Step Increment The variable `angle` is only initialised once (line 30) and accumulates across all loop iterations and even across successive input cycles. This means each new drawing session continues rotating from wherever the previous one ended, which can produce unexpected results if the user expects a fresh start without choosing CLS. The variable `forward` is increased by `incstep` at line 125 each iteration, enabling spiral or expanding-polygon forms when `incstep` is non-zero. ### Key Variables | Variable | Purpose | | --- | --- | | `repeat` | Number of line segments to draw per cycle | | `right` | Degrees added to `angle` each step | | `forward` | Current segment length in pixels | | `incstep` | Amount added to `forward` each step | | `angle` | Persistent cumulative heading in degrees | | `a$` | User’s yes/no choice for clearing the screen | ### Notable Techniques and Anomalies - The initial `PLOT 127,87` on line 70 centres the drawing cursor at approximately the middle of the 256×176 graphics area before drawing begins — but only when the user chooses to clear the screen. If no CLS is performed, the cursor remains wherever the previous `DRAW` left it. - Accepting both `"y"` and `"Y"` for the clear prompt (line 70) is a good defensive input practice; however, any other input, including `"n"`, silently skips the CLS without confirmation. - Because `angle` is not reset between input cycles, a user who wants a genuinely fresh start must answer Y to the clean prompt AND be aware that the heading continues from its prior value — the CLS only clears the screen, not the state. - Setting `incstep=0` produces regular polygons or stars; non-zero values yield Archimedean spiral variants. ## Source Code ``` 1 REM "TINY TURTLE" 2 REM By Tim Hartnell ? 3 REM Your Sinclair June 86 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 forward=forward+incstep 130 NEXT a 140 GO TO 40 ```