Text Tiles

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

This program generates an endlessly scrolling screen of pseudo-random textile-like patterns using block graphics and alphanumeric characters. It builds a 9-character string where each character is either a printable ASCII character (codes 32–42) or its inverse-video equivalent, chosen by adding 128 when a second random number exceeds 0.5. The full screen is filled by printing the 9-character string 78 times plus the first 2 characters, totalling 704 characters to fill a 32×22 display. The loop restarts from line 20 each iteration, regenerating the pattern string before redrawing.


Program Analysis

Program Structure

The program is a tight infinite loop across three phases: string generation (lines 10–40), screen printing (lines 50–90), and restart (line 100). There is no user interaction; it runs continuously until interrupted.

  1. Lines 10–40: Dimension and fill a 9-character string G$ with randomly selected characters.
  2. Lines 50–90: Clear the cursor to the top-left and print the pattern to fill the screen.
  3. Line 100: GOTO 20 skips the DIM at line 10, regenerating the string without re-dimensioning.

Character Generation (Line 30)

Each character is chosen by:

  • INT(RND*11) — selects a base character in the range 0–10, which when added to a minimum of 32 gives codes 32–42 (space through *).
  • (RND>.5)*128 — with roughly 50% probability, adds 128 to produce the inverse-video version of that character.

The result is a character that is either a low printable ASCII symbol or its inverse counterpart. The combination of normal and inverse characters at the same base codepoints creates the woven textile appearance.

Screen Filling Strategy

The ZX81 screen is 32 columns × 24 rows = 768 characters. The program prints G$ (9 characters) 78 times (702 characters) then prints G$(TO 2) (2 characters), for a total of 704 characters. Starting at AT 0,0, this fills 22 full rows (704 = 22×32), leaving the bottom status rows untouched — a practical choice to avoid interfering with the system area.

ActionCharacters printed
G$ × 78 iterations702
G$(TO 2)2
Total704 (22 rows)

Notable Techniques

  • Slice printing for exact fill: G$(TO 2) uses a string slice to print exactly the remainder needed after the 78 full copies, avoiding screen scroll or overflow.
  • Skipping DIM on re-entry: GOTO 20 bypasses line 10, so the array is only dimensioned once at startup. Re-entering at line 20 simply overwrites the existing string contents.
  • Dual-RND inverse selection: Using a separate RND>.5 boolean expression (evaluating to 0 or 1) multiplied by 128 is a compact idiom for a 50/50 attribute flip without needing an IF statement.
  • PRINT AT 0,0; without clearing: Printing directly over the previous frame without CLS avoids a flash between frames, keeping the animation smooth.

Potential Anomalies

The base range INT(RND*11) produces values 0–10. Without an explicit offset these would be control characters (codes 0–10). However, on the ZX81, CHR$ of codes below 32 still produces displayable graphic characters rather than control codes, so the output remains visible — this is intentional exploitation of the ZX81 character set rather than a bug.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10122 – 10175.

Related Products

Related Articles

Related Content

Image Gallery

Text Tiles

Source Code

   5 REM TEXT(ILES)
  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);
 100 GOTO 20
 110 SAVE "1013%0"
 120 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