Patterns

This file is part of and Timex Sinclair Public Domain Library Tape 1002. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Demo, Graphics

This program generates a continuously refreshing screen of pseudo-random block-graphic patterns. It builds a 9-character string where each character is either a printable character or its inverse-video equivalent, chosen using a combined RND expression: `INT(RND*11)` selects from the first 11 characters of the character set, while `(RND>.5)*128` adds 128 to produce the inverse form roughly half the time. The string is then printed 78 times plus a 2-character tail to fill the ZX81’s 32-column display, and the pattern refreshes every 2 seconds (PAUSE 120) in an infinite loop.


Program Analysis

Program Structure

The program is compact and straightforward, organised into a single loop with no subroutines:

  1. Lines 10–40: Initialise and fill a 9-character string G$ with randomly chosen characters.
  2. Lines 50–90: Print the string repeatedly to fill the screen, then pause for 2 seconds (PAUSE 120 = 120 × 1/50 s = 2.4 s on a 50 Hz machine).
  3. Line 100: Loop back to regenerate the pattern.

Character Generation Technique

Line 30 is the heart of the program:

LET G$(I)=CHR$ (INT(RND*11)+(RND>.5)*128)

This combines two independent RND calls into a single expression. INT(RND*11) yields a value from 0 to 10, selecting characters from the very start of the character set (space through the 10th character, which on the ZX81 includes the block graphics at codes 1–10). The boolean expression (RND>.5)*128 evaluates to either 0 or 128 with roughly equal probability, toggling inverse video on roughly half the characters. The result is a 9-character string of mixed normal and inverse block/space characters.

Screen Filling Logic

The ZX81 display is 32 columns wide. The 9-character string G$ is printed 78 times in line 70, yielding 702 characters. The screen holds 24 rows × 32 columns = 768 character positions, so 78 full repetitions account for 702 characters. Line 90 then prints the first 2 characters of G$ (using the slice G$(TO 2)), bringing the total to 704 — not quite 768. The AT 0,0 in line 50 resets the print position to the top-left before each refresh, overwriting the previous pattern cleanly.

Notable Techniques and Idioms

  • Boolean arithmetic: (RND>.5)*128 exploits the ZX81’s representation of boolean TRUE as 1 and FALSE as 0 to conditionally add 128 without an IF statement.
  • String slicing: G$(TO 2) on line 90 is a clean ZX81 BASIC substring idiom to print just the first two characters of the tile string as a screen-width filler.
  • PAUSE for animation rate: PAUSE 120 introduces a fixed delay between refreshes, giving the viewer time to perceive each pattern before the next is generated.
  • REM with inverse video: Line 5 uses inverse-video characters to spell “PATTERNS” in the REM statement, serving as a visible program title in the listing.

Potential Anomalies

The screen fill is slightly short: 78 × 9 + 2 = 704 characters rather than 768. The bottom portion of the screen (64 characters, or 2 rows) will not be overwritten on the first pass if the cursor does not scroll. However, since the program loops indefinitely with AT 0,0, any residual content from a prior iteration will be overwritten as the print position advances naturally through those positions during subsequent cycles. No functional bug results, though the very last two rows may momentarily show stale data on the first iteration only.

Variable Summary

VariablePurpose
G$9-character tile string of random (possibly inverse) block characters
ILoop counter used for both string initialisation (1–9) and screen printing (1–78)

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10051 – 10121.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   5 REM %P%A%T%T%E%R%N%S
  10 DIM G$(9)
  20 FOR I=1 TO 9
  30 LET G$(I)=CHR$ (INT (RND*11)+(RND>.5)*128)
  40 NEXT I
  50 PRINT AT 0,0;
  60 FOR I=1 TO 78
  70 PRINT G$;
  80 NEXT I
  90 PRINT G$( TO 2);
  95 PAUSE 120
 100 GOTO 20
 200 SAVE "1006%5"
 210 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top