--- title: "Circle Fill" id: 71181 type: "computer_media" slug: "circle-fill" url: "http://localhost/computer_media/circle-fill/" markdown_url: "http://localhost/computer_media/circle-fill.md" published_at: "2026-08-31T07:38:11+00:00" modified_at: "2026-08-31T07:38:11+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/08/circle-fill.png" alt: "Circle Fill screen" excerpt: "A clever scan-line algorithm fills a circle using Pythagorean geometry, accepting custom ink color, center coordinates, and radius — all in under ten lines." 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/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Circle%20Fill%20%28198x%29%28-%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2026/08/circle-fill.png" alt: "Circle Fill screen" media_type_tags: "Demo" --- # Circle Fill Circle Fill draws a filled circle on screen by combining the built-in CIRCLE command with a scan-line fill algorithm. The program accepts user-specified ink color, center coordinates, and radius, then iterates from N=0 to R, computing the horizontal half-chord length at each vertical offset using the Pythagorean relationship XX=SQR(R²−N²). Two vertical DRAW strokes are plotted symmetrically on either side of the center X coordinate to paint the interior column by column. Because it fills using vertical line segments rather than horizontal scan lines, it exploits the PLOT/DRAW command pair efficiently without needing to track left and right pixel boundaries per row. *** ### Program Structure The program is a short, linear routine with no subroutines or complex branching. It collects five inputs (ink color, X, Y, and radius), draws the circle outline using the built-in `CIRCLE` command at line 35, then fills the interior with a `FOR` loop spanning lines 40–90. | Lines | Purpose | | --- | --- | | 1 | Input ink color `A` | | 5 | Set INK, PAPER, and BORDER attributes | | 10–30 | Input center coordinates `X`, `Y`, and radius `R` | | 35 | Draw circle outline with built-in `CIRCLE` | | 40–90 | Fill loop: iterate `N` from 0 to `R`, plot vertical chords | ### Fill Algorithm The fill works by iterating `N` across the horizontal range 0 to `R`. For each column offset `N`, the half-chord height `XX` is computed as `SQR(R²−N²)` — a direct application of the Pythagorean theorem. Two vertical line segments are then drawn: one at `X+N` and one at `X−N`, both starting at `Y+XX` and extending downward by `2*XX`. This symmetrically fills left and right halves of the circle simultaneously, meaning each pass covers two columns at once (except at `N=0`, where both `PLOT`/`DRAW` pairs coincide on the center column). ### Key BASIC Idioms - `LET Z=R^2` and `LET ZZ=N^2` at line 50 cache the squared values to avoid recomputing them twice within the same iteration — a minor but sensible optimization in interpreted BASIC. - `DRAW 0,-XY` draws a purely vertical line downward of length `2*XX`, making use of the two-argument form of `DRAW` with zero horizontal displacement. - The `INK A:PAPER 0:BORDER 0` idiom at line 5 chains attribute-setting commands on a single line, keeping the setup compact. ### Notable Techniques Using vertical chord segments rather than horizontal scan lines is an unconventional but valid approach. Horizontal scan-line filling is more common because display memory is organized in rows, but vertical chord filling is geometrically equivalent and requires no per-row boundary tracking. The trade-off is that for large radii, very thin columns near the edges (where `N` approaches `R`) will have very short chords, and floating-point rounding in `SQR` could leave occasional unfilled pixels near the circle’s leftmost and rightmost extremes. ### Potential Issues and Anomalies - Line 1 inputs `A` for ink color but provides no prompt string, which may confuse users unfamiliar with the expected input order. - No bounds checking is performed: entering coordinates or a radius that would cause pixels to fall outside the screen area will produce an error rather than clipping gracefully. - At `N=0`, both `PLOT X+0,YY: DRAW 0,-XY` and `PLOT X-0,YY: DRAW 0,-XY` address the same column, resulting in the center vertical chord being drawn twice — a harmless but redundant operation. - The `CIRCLE` at line 35 draws the outline before the fill loop runs. Depending on floating-point precision in the chord computation, the fill may not perfectly reach the outline in all directions, potentially leaving a thin gap at the perimeter. ## Source Code ``` 1 INPUT A 5 INK A:PAPER 0:BORDER 0 10 INPUT "X COORDINATE (0-255) ";X 20 INPUT "Y COORDINATE (0-175) ";Y 30 INPUT "RADIUS ";R 35 CIRCLE X,Y,R 40 FOR N=0 TO R 50 LET Z=R^2:LET ZZ=N^2 55 LET XX= SQR (Z-ZZ) 60 LET YY=Y+XX:LET XY=2*XX 70 PLOT X+N,YY:DRAW 0,-XY 80 PLOT X-N,YY:DRAW 0,-XY 90 NEXT N ```