This program draws a horizontal line of a randomly chosen printable character across a random row of the screen, then erases it by overwriting with spaces, looping indefinitely. The line length is a random value from 1 to 21 columns, the row is randomly chosen from rows 1 to 19, and the character is selected from the printable ASCII range (codes 33–255). The double comma after each PRINT statement suppresses the newline and advances the print position, building the line one character at a time. The program creates a simple animation effect of a character string appearing and disappearing across the screen.
Program Analysis
Program Structure
The program is a short, self-contained infinite animation loop. After an initial REM label at line 10, it generates three random values, draws a line, then erases it before jumping back to regenerate new values. There are no subroutines or conditional branches.
- Initialization (lines 20–40): Three random variables are computed — line length
L, screen rowL1, and character codeJ. - Draw phase (lines 50–80): A
FORloop placesCHR$ Jat successive columns from 0 toL, followed by a redundant extra print at columnL. - Erase phase (lines 90–110): A reverse
FORloop overwrites columnsL-1down to 0 with spaces. - Loop (line 120):
GO TO 20restarts the cycle with newly randomized values.
Variable Usage
| Variable | Range | Purpose |
|---|---|---|
L | 1–21 | Length of the character line (columns) |
L1 | 1–19 | Screen row for the line |
J | 33–255 | Character code to display |
F | 0 to L or L-1 to 0 | Loop counter / column index |
Notable Techniques
- Double comma in PRINT: The
,,afterCHR$ Jin lines60and80suppresses the automatic newline and moves the cursor to the next column, enabling character-by-character horizontal drawing without repositioning viaATeach time after the first. - Random character selection:
INT(RND*223)+33spans codes 33–255, covering all printable ASCII characters as well as the block graphics and UDG character set, so the visual output varies widely between cycles. - In-place erase animation: Rather than using
CLS, the erase phase walks backwards across the drawn columns, creating a wipe effect rather than a flash clear.
Bugs and Anomalies
- Off-by-one / redundant print at line 80: The
FORloop at lines50–70already prints at columnLduring its final iteration (F=L), so line80prints the same character atAT L1,Lagain. This is harmless but redundant. - Erase starts at L-1, not L: The erase loop (line
90) runs fromL-1down to0, leaving the character at columnLpermanently on screen until the next cycle draws over it (if the new line is at least as long) or it persists otherwise. This means the rightmost character is never erased within the current cycle. - Row range avoids row 0:
L1starts at 1, so the top row is never used for drawing — this may be intentional to avoid interfering with system output, or simply an oversight.
Content
Source Code
10 REM *** MUFFIN
20 LET L=INT (RND*21)+1
30 LET L1=INT (RND*19)+1
40 LET J=INT (RND*223)+33
50 FOR F=0 TO L
60 PRINT AT L1,F;CHR$ J,,
70 NEXT F
80 PRINT AT L1,L;CHR$ J,,
90 FOR F=(L-1) TO 0 STEP -1
100 PRINT AT L1,F;" "
110 NEXT F
120 GO TO 20
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
