STAR draws fully connected regular n-sided polygons by computing vertex positions using trigonometry and then drawing a line between every pair of vertices, producing a dense star-like pattern. The user inputs the number of points, and the program calculates vertex coordinates centered at (120, 90) with a radius of 70 pixels using COS and SIN of evenly spaced angles. The nested FOR loops at lines 150–190 implement an O(n²) algorithm, connecting each vertex i to every subsequent vertex j, with a short PAUSE 30 and an INKEY$ check between each DRAW call so the user can pause the drawing mid-progress. The program uses BORDER, INK, PAPER, and FLASH attributes for visual presentation and loops back to accept a new value of n after each figure is drawn.
Program Structure
The program is organized into three broad phases: an introductory splash screen (lines 2–27), a user-input and setup phase (lines 30–80), and a drawing loop with exit handling (lines 100–240). After completing a figure, line 240 sends control back to line 30 to restart, creating an indefinite interactive loop.
Vertex Calculation
Lines 70–140 compute the Cartesian coordinates of each vertex of a regular n-gon. The angular step a is set to 2*PI/n at line 70, and for each vertex i, the position is:
x(i) = cx + s * COS(a*(i-1))y(i) = cy + s * SIN(a*(i-1))
The centre is fixed at pixel coordinates (120, 90) and the radius s is 70 pixels, placing the figure comfortably on screen. Coordinates are stored in two floating-point arrays x(n) and y(n) allocated with DIM at line 50.
Drawing Algorithm
Lines 150–190 use a nested loop to connect every vertex to every other vertex exactly once, yielding a complete graph Kn on the polygon’s vertices. The outer loop runs i from 1 to n-1 and the inner loop runs j from i+1 to n, so each pair is visited once. For an n-pointed figure this produces n*(n-1)/2 line segments, which grows quickly — for example, 10 points produce 45 lines.
Interactive Pause Feature
Inside the inner drawing loop, lines 185–186 implement a pause-on-keypress mechanism. PAUSE 30 introduces a short delay between each segment. If any key is detected via INKEY$, a PAUSE 0 is executed, halting until another key is pressed. This allows the user to freeze the picture at any intermediate stage without breaking the loop.
Exit and Restart Logic
After a figure is complete, line 220 prompts the user, and lines 222–225 wait for a definite keypress using a PAUSE 0 followed by a spin loop that exits only when INKEY$ is non-empty. Line 230 tests for "x" to trigger a farewell message and STOP; any other key falls through to line 240 which restarts the whole cycle.
Notable Anomalies
- Line 7 contains a typo:
"n-sided figuras"(Spanish/Portuguese plural) rather than “figures”. This is a cosmetic error only. - Line 26 uses a double semicolon (
;;), which results in theFLASH 1attribute being set and then the cursor position not advancing before the string — effectively a no-op spacing artifact rather than a functional bug. - The guard at line 45 (
IF n<=1 THEN CLS: GO TO 40) prevents degenerate cases of 0 or 1 vertices, but does not guard against negative input, which would also causeDIMto error. - Line 225 busy-waits on
INKEY$=""after aPAUSE 0, meaning by the time line 225 is reached the key may already have been released, potentially causing an immediate loop back rather than correctly reading the intended key on line 230. This is a classic race condition withPAUSE 0/INKEY$sequencing. INK 2is set inside the inner loop at line 180 but never reset; the firstPLOTat line 175 will use whatever ink color is current, which after the first iteration will also be INK 2 (red).
Variable Summary
| Variable | Purpose |
|---|---|
n | Number of polygon vertices (user input) |
a | Angular step between vertices (2π/n) |
cx, cy | Centre pixel coordinates (120, 90) |
s | Radius in pixels (70) |
t | Angle for current vertex |
x(n), y(n) | Arrays of vertex pixel coordinates |
i, j | Loop indices for vertex pairs |
Source Code
2 CLS : PRINT AT 10,8; FLASH 1;"STOP THE TAPE "
4 PAUSE 300: CLS
5 BORDER 4: INK 1: PAPER 5
6 PRINT AT 4,2;"This program draws regular"
7 PRINT AT 5,7;"n-sided figuras"
20 PRINT AT 7,0;"To stop the picture at any time press any key. Pressing another key will begin the drawing again"
26 PRINT AT 15,3; FLASH 1;;"To continue press any key"
27 PAUSE 0
30 CLS
40 INPUT "TYPE in how many points you wantthe star to have- then press theenter key";n
45 IF n<=1 THEN CLS : GO TO 40
50 DIM x(n): DIM y(n)
65 PRINT AT 0,8;n;"- sided figure"
70 LET a=2*PI/n
80 LET cx=120: LET cy=90: LET s=70
100 FOR i=1 TO n
110 LET t=a*(i-1)
120 LET x(i)=cx+s*COS t
130 LET y(i)=cy+s*SIN t
140 NEXT i
150 FOR i=1 TO n-1
170 FOR j=i+1 TO n
175 PLOT x(i),y(i)
180 INK 2: DRAW x(j)-x(i),y(j)-y(i)
185 PAUSE 30
186 IF INKEY$<>"" THEN PAUSE 0
190 NEXT j: NEXT i
220 PRINT AT 20,0;"press x to exit otherwise press any key"
222 PAUSE 0
225 IF INKEY$="" THEN GO TO 225
230 IF INKEY$="x" THEN CLS : PRINT AT 10,10; FLASH 1;"**bye**": STOP
240 GO TO 30
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
