--- title: "Sphere 3D" id: 53031 type: "computer_media" slug: "sphere-3d" url: "http://localhost/computer_media/sphere-3d/" markdown_url: "http://localhost/computer_media/sphere-3d.md" published_at: "2024-02-04T23:11:41+00:00" modified_at: "2026-03-30T21:45:30+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/02/Sphere-3D.png" excerpt: "A parametric curve plotter stores every screen coordinate as packed characters, then redraws the Lissajous-style figure instantly from its own memory buffer." 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: "Real Gagnon" slug: "real-gagnon" taxonomy: "indiv" url: "http://localhost/indiv/real-gagnon/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_type: "Program" programmers: - name: "Real Gagnon" slug: "real-gagnon" taxonomy: "indiv" url: "http://localhost/indiv/real-gagnon/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Sphere%203D%20%281985%29%28Gagnon%2C%20Rene%29%28Canada%29%28TS2068%29%28Program%29.zip" mediadate: "1985" images: - url: "http://localhost/wp-content/uploads/2024/02/Sphere-3D.png" article_media: - id: 52998 title: "Programme: Sphere 3D" type: "article" url: "http://localhost/article/programme-sphere-3d/" media_type_tags: "Demo" --- # Sphere 3D This program plots a Lissajous-style parametric curve on the screen using the equations x = 125 + g·sin(a) and y = 87 + g·sin(0.95a)·cos(a), where g is a user-supplied size value and a steps from 0 to 125.7 in increments of 0.03. The resulting shape is a closed or near-closed figure-eight or knot pattern depending on the irrational frequency ratio (0.95). After drawing, all plotted points are stored in the string array b$, with each coordinate packed as a single CHR$ character, allowing the curve to be redrawn from memory without recalculating. The program uses a 4200-element two-character-wide string array to buffer coordinates, exploiting the fact that screen coordinates fit within the 0–255 range of a single byte stored as a character code. Redrawing from the buffer on the second pass demonstrates an efficient coordinate caching technique using CODE to recover the numeric values from stored characters. *** ## Program Analysis ### Program Structure The program divides into three logical phases: 1. **Initialization (line 5):** Sets display attributes, clears the screen, and dimensions the coordinate buffer array. 2. **Plotting loop (lines 20–50):** Prompts for a size parameter, iterates through the parametric angle, computes and plots each point, and stores coordinates in the buffer. 3. **Redraw phase (lines 100–110):** Waits for a keypress, clears the screen, and replots the entire curve from the buffered data. ### Parametric Equations The curve is defined by: - `x = 125 + g * SIN(a)` - `y = 87 + g * SIN(0.95 * a) * COS(a)` The parameter `a` runs from 0 to 125.7 in steps of 0.03, giving approximately 4190 points. The irrational frequency ratio of 0.95 (= 19/20) means the x and y oscillations have a near but not exactly integer relationship, producing a dense, slowly precessing Lissajous-like figure. The center is offset to approximately the middle of the 256×176 pixel display area. ### Coordinate Buffer Technique The array `b$(4200,2)` is declared as a two-column string array, where each element holds a single character. The x coordinate is stored as `CHR$(x)` in column 1, and the y coordinate as `CHR$(y)` in column 2. During the redraw phase, `CODE b$(a,1)` and `CODE b$(a,2)` recover the numeric values. This is an efficient packing scheme that exploits the 0–255 range of a character code matching the screen coordinate space exactly, avoiding any floating-point recalculation on the second pass. ### Key BASIC Idioms | Line | Idiom | Purpose | | --- | --- | --- | | `5` | `DIM b$(4200,2)` | Allocates a fixed-size 2-column string array as a coordinate store | | `40` | `CHR$(x)` / `CHR$(y)` | Packs integer coordinates into single characters for compact storage | | `100` | `FLASH 1` / `PAUSE 0` | Attracts attention then waits for any keypress before redrawing | | `110` | `CODE b$(a,1)` | Unpacks stored character back to its numeric coordinate value | ### Notable Techniques The use of `PRINT #0;` on line 100 directs the flashing prompt to the lower status area (stream 0) rather than the main screen, preserving the drawn curve while awaiting user input. The counter variable `c` tracks how many points were actually plotted, so the redraw loop on line 110 iterates exactly `c-1` times rather than assuming all 4200 slots are populated. ### Potential Issues With a step of 0.03 over a range of 125.7, the loop generates approximately 4190 iterations. The buffer is sized at 4200, leaving a small safety margin of about 10 elements. However, if `g` is large enough to push computed `x` or `y` values outside the 0–255 range, `CHR$` would produce an error. No bounds checking is performed on the coordinate values before storing them, which could cause an out-of-range error for very large size inputs. ## Source Code ``` 5 BORDER 0: PAPER 0: INK 5: CLS : DIM b$(4200,2) 20 LET c=1: INPUT "Size:";g 30 FOR a=0 TO 125.7 STEP .03: LET y=87+g*SIN (a*.95)*COS a: LET x=125+g*SIN a 40 PLOT x,y: LET b$(c,1)=CHR$ (x): LET b$(c,2)=CHR$ (y) 50 LET c=c+1: NEXT a 100 PRINT #0; FLASH 1;"Press a key...": PAUSE 0: CLS 110 FOR a=1 TO c-1: PLOT CODE b$(a,1),b$(a,2): NEXT a ```