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^2andLET ZZ=N^2at 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,-XYdraws a purely vertical line downward of length2*XX, making use of the two-argument form ofDRAWwith zero horizontal displacement.- The
INK A:PAPER 0:BORDER 0idiom 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
Afor 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, bothPLOT X+0,YY: DRAW 0,-XYandPLOT X-0,YY: DRAW 0,-XYaddress the same column, resulting in the center vertical chord being drawn twice — a harmless but redundant operation. - The
CIRCLEat 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.
Content
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
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
