Network

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Art, Demo

This program draws a radiating line-burst graphic centered on the screen, creating a network or moire pattern. It uses two nested loops to draw lines from a central point (128,88) to points along the bottom edge and then up the right side of the display, with the direction variable `z` flipping between 1 and −1 on each pass to mirror the pattern. Random ink and paper colors are chosen each cycle, with a retry loop ensuring they never match. The finished frame is held briefly with PAUSE 100 before the display is cleared and a new color combination is generated.


Program Analysis

Program Structure

The program is a continuous animation loop. Execution begins at line 10 (a REM label), sets up colour and direction state, draws the pattern, pauses, then jumps back to line 20 indefinitely.

  1. Lines 20–55 — Initialise direction variable z, pick random ink and paper colours (1–5), retry if they match, then apply colours and clear the screen.
  2. Lines 60–130 — Outer FOR a=1 TO 2 loop runs the drawing phase twice; on the second pass z is negated at line 130, mirroring the geometry.
  3. Lines 70–90 — Inner loop draws lines from centre (128,88) to points along the horizontal axis, stepping every 2 pixels.
  4. Lines 100–120 — Second inner loop draws lines from centre to points along the vertical axis.
  5. Line 140 — Negate z, close outer loop, pause 100 frames (~2 seconds), then restart.

Drawing Geometry

All lines originate from the fixed point (128, 88), which is close to the screen centre (the display is 256×176 pixels, so true centre is 128,88 — this is exact). The DRAW command takes relative offsets; the expressions (-127*z)+(x*z) and z*-87 etc. scale the endpoint by z (±1), so the second pass of the outer loop reflects every line through the origin, producing a symmetrical starburst.

Key BASIC Idioms

  • Direction flip via negation: LET z=-z at line 130 toggles z between 1 and −1, avoiding a conditional branch and neatly mirroring the draw operations.
  • Colour collision avoidance: The IF ink=paper THEN GO TO 30 retry at line 50 is a simple rejection-sampling loop ensuring readable contrast.
  • Colour range 1–5: Using INT(RND*5)+1 excludes black (0) and white (7), keeping all combinations visually distinct on a non-black, non-white background.
  • STEP 2 sampling: Both loops step by 2 pixels, halving draw time while still producing a dense fan of lines.

Notable Techniques

The outer FOR a=1 TO 2 loop is an elegant way to draw a mirrored set of lines without duplicating code. On the first iteration (z=1) lines radiate toward the lower-left and lower quadrants; after LET z=-z (line 130) sets z=-1, the second iteration reflects them to the upper-right quadrants, filling the screen with a symmetrical network pattern.

The PAPER and INK statements at line 55 are followed immediately by CLS, ensuring the entire screen — including the border attribute area — is repainted in the new colour scheme before drawing begins.

Variable Summary

VariableRole
zDirection multiplier (1 or −1); mirrors draw geometry on second pass
inkRandom foreground colour (1–5)
paperRandom background colour (1–5), guaranteed ≠ ink
aOuter loop counter (1–2); drives two mirrored drawing passes
xHorizontal pixel offset (0–254, step 2)
yVertical pixel offset (0–175, step 2)

Potential Anomalies

On the second pass of the outer loop, z has already been set to −1 at line 130, but line 130 is inside the outer FOR/NEXT loop (lines 60–140). This means z is negated after the first complete set of fan lines and before the second, which is the intended behaviour. However, z is also reset to 1 unconditionally at line 20 each time the main loop restarts via GO TO 20, so state is always clean at the start of each frame.

Content

Appears On

Capital Area Timex Sinclair User Group’s Library Tape.

Related Products

Related Articles

Related Content

Image Gallery

Network

Source Code

   10 REM network
   20 LET z=1
   30 LET ink=INT (RND*5)+1
   40 LET paper=INT (RND*5)+1
   50 IF ink=paper THEN GO TO 30
   55 PAPER paper: INK ink: CLS 
   60 FOR a=1 TO 2
   70 FOR x=0 TO 254 STEP 2
   80 PLOT 128,88: DRAW (-127*z)+(x*z),z*-87
   90 NEXT x
  100 FOR y=0 TO 175 STEP 2
  110 PLOT 128,88: DRAW 127*z,z*-87+(y*z)
  120 NEXT y
  130 LET z=-z
  140 NEXT a: PAUSE 100: GO TO 20
 9990 SAVE "NETWORK" LINE 10

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

People

No people associated with this content.

Scroll to Top