--- title: "Text Tiles" id: 57240 type: "computer_media" slug: "text-tiles" url: "http://localhost/computer_media/text-tiles/" markdown_url: "http://localhost/computer_media/text-tiles.md" published_at: "2024-10-04T07:07:30+00:00" modified_at: "2026-03-30T21:19:06+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/130_TxtT.png" excerpt: "An infinite stream of randomly generated textile-like patterns floods the screen, mixing normal and inverse characters for a mesmerising woven effect." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_contents: - id: 56734 title: "Timex Sinclair Public Domain Library Tape 1003" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1003/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/130_TxtT.png" media_type_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. | Action | Characters printed | | --- | --- | | `G$` × 78 iterations | 702 | | `G$(TO 2)` | 2 | | **Total** | **704 (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. ## 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 ```