Circle Fill

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Demo

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.

LinesPurpose
1Input ink color A
5Set INK, PAPER, and BORDER attributes
10–30Input center coordinates X, Y, and radius R
35Draw circle outline with built-in CIRCLE
40–90Fill 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.

Content

Appears On

Related Products

Related Articles

Related Content

Image Gallery

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.

People

No people associated with this content.

Scroll to Top