--- title: "Spiral" id: 56318 type: "computer_media" slug: "spiral" url: "http://localhost/computer_media/spiral/" markdown_url: "http://localhost/computer_media/spiral.md" published_at: "2024-08-04T10:50:00+00:00" modified_at: "2026-03-30T21:45:30+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/08/SCR-20240803-jned.png" excerpt: "A pure-BASIC geometric spiral built from trigonometric rotation and scaling draws an intricate hexagonal pattern — ported from Apple II code published in Creative Computing, February 1984." 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: "Joe Jenkins" slug: "joe-jenkins" taxonomy: "indiv" url: "http://localhost/indiv/joe-jenkins/" - name: "Ted Knyszek" slug: "ted-knyszek" taxonomy: "indiv" url: "http://localhost/indiv/ted-knyszek/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" 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: "Joe Jenkins" slug: "joe-jenkins" taxonomy: "indiv" url: "http://localhost/indiv/joe-jenkins/" - name: "Ted Knyszek" slug: "ted-knyszek" taxonomy: "indiv" url: "http://localhost/indiv/ted-knyszek/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Spiral%20%281988%29%28Jenkins%2C%20Joe%20E.%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "1988" images: - url: "http://localhost/wp-content/uploads/2024/08/SCR-20240803-jned.png" media_type_tags: "Demo" --- # Spiral This program draws a geometric spiral pattern on screen using trigonometric rotation and scaling. It initialises cosine and sine values for two rotation angles — 60° (PI/3) for the inner hexagonal step and 5° (PI/36) for the outer spiral progression — then iterates 43 spiral arms each composed of 6 line segments drawn with PLOT and DRAW. A scaling factor of 0.95 (sf) shrinks the radius slightly on each outer iteration, producing the inward spiral effect. An aspect-ratio correction factor (sc=1.16) compensates for the non-square pixel geometry of the display. *** ## Program Analysis ### Program Structure The program is a straightforward iterative graphics routine with no subroutines or user input. After initialisation (lines 20–110), it enters a double loop: the outer `FOR j` loop (line 120) runs 43 times for each spiral arm, and the inner `FOR i` loop (line 130) runs 7 times (0 to 6) to draw 6 line segments per arm. After all drawing is done, execution ends at `STOP` on line 280. ### Variable Initialisation | Variable | Value | Purpose | | --- | --- | --- | | `c` | COS(PI/3) | Cosine of 60° — inner rotation step | | `s` | SIN(PI/3) | Sine of 60° — inner rotation step | | `c1` | COS(PI/36) | Cosine of 5° — outer spiral progression | | `s1` | SIN(PI/36) | Sine of 5° — outer spiral progression | | `sf` | 0.95 | Scale factor per outer iteration (shrinks radius) | | `x`, `y` | 95, 0 | Initial vector coordinates | | `cx`, `cy` | 130, 88 | Screen centre offset | | `sc` | 1.16 | Horizontal aspect-ratio correction | ### Drawing Mechanism Within the inner loop, screen coordinates `sx` and `sy` are computed by applying the aspect-ratio scale to `x` and adding the centre offsets. On the first pass (`i=0`), the branch at line 160 skips the draw call and simply records the starting point into `sx1`/`sy1`. On subsequent passes, `PLOT sx1,sy1` followed by `DRAW (sx-sx1),(sy-sy1)` draws a relative line segment to the new point. This PLOT-then-DRAW idiom is a standard Sinclair BASIC technique for connecting successive coordinate pairs. ### Rotation Mathematics The 2D rotation matrix is applied explicitly each iteration. Lines 200–220 rotate the vector `(x,y)` by 60° using the standard formulae: - `xn = x·cos θ − y·sin θ` - `y = x·sin θ + y·cos θ` - `x = xn` (temporary variable avoids overwriting `x` before it is used) The same pattern is repeated at lines 240–260 for the 5° outer rotation, with the additional multiplication by the scale factor `sf` to progressively reduce the spiral radius. ### Notable Techniques - **Pre-computed trig values:** All cosine and sine values are computed once before the loops, avoiding repeated and expensive floating-point trig calls inside the tight double loop. - **Aspect-ratio correction:** The value `sc=1.16` applied only to the `x` coordinate compensates for the rectangular pixel shape of the display, keeping the spiral visually circular. - **Temporary variable for rotation:** The use of `xn` as a scratch variable when computing the rotation ensures the old value of `x` is preserved for the `y` calculation, a necessary correctness technique. - **Multiple statements on one line:** Line 190 uses the colon separator to store both `sx1` and `sy1` in one logical line, a common BASIC compactness idiom. ### Potential Anomalies The inner loop runs `FOR i=0 TO 6`, which is 7 iterations, but only 6 actual line segments are drawn (the first iteration at `i=0` merely initialises the starting point). This is intentional: it produces a closed or near-closed hexagonal step per arm. The choice of 43 outer iterations combined with a 5° rotation step gives 43 × 5° = 215° of total outer rotation, meaning the spiral does not complete a full revolution, which appears to be a deliberate aesthetic choice inherited from the original Apple II program. ## Source Code ``` 1 REM "SPIRAL" 2 REM By Joe E. Jenkins 3100 Mockingbird Amarillo, TX 79109 11 NOV 85 3 REM a conversion by Ted Knyszek from Apple II to TS-2068 See Creative Computing Feb 1984 20 LET c=COS (PI/3) 30 LET s=SIN (PI/3) 40 LET c1=COS (PI/36) 50 LET s1=SIN (PI/36) 60 LET sf=.95 70 LET x=95 80 LET y=0 90 LET cx=130 100 LET cy=88 110 LET sc=1.16 120 FOR j=1 TO 43 130 FOR i=0 TO 6 140 LET sx=x*sc+cx 150 LET sy=cy+y 160 IF i=0 THEN GO TO 190 170 PLOT sx1,sy1 180 DRAW (sx-sx1),(sy-sy1) 190 LET sx1=sx: LET sy1=sy 200 LET xn=x*c-y*s 210 LET y=x*s+y*c 220 LET x=xn 230 NEXT i 240 LET xn=sf*(x*c1-y*s1) 250 LET y=sf*(x*s1+y*c1) 260 LET x=xn 270 NEXT j 280 STOP ```