PATTERNS

Some very beautiful patterns can be generated from a very simple set of rules. The following program creates a variety of unpredictable patterns, containing many curves, simply by drawing a series of line segments. The lines are drawn between two points which move in straight lines across the screen. When either point reaches the edge of the screen it is reflected, like a billiard ball. On reaching a certain complexity the pattern is undrawn, line by line, resulting in startling effects as parts of the pattern are eliminated before others.

Sample plot:


BBC Computer Version

The BBC Computer version uses integer variables for maximum speed, and the 4-colour graphics mode available on the Model A. Successive lines are drawn in different colours to give a rainbow effect.

10 REM ... Patterns
20 C%=1
30 DIM XX%(3),ZZ%(3),VV%(3),CC%(3),WW%(3)

Choose 160x256 4-colour graphics mode. Define logical colour zero (background) as physical colour 4 (blue), and logical colour 3 (white) as physical colour 2 (green); turn cursor off.

40 REPEAT MODE5
45 VDU19,0,4;0;19,3,2;0;23;&200A;0;0;0;
50 CC%(0)=1280:CC%(1)=1024:CC%(2)=CC%(0):CC%(3)=CC%(1)
60 FOR I%=0T03:XX%(I%)=ABSRND:VV%(I%)=ABSRND MOD4*8
70 XX%(I%)=XX%(I%) MOD CC%(I%):ZZ%(I%)=XX%(I%)+CC%(I%):NEXT
80 FOR G%=5T07 STEP2

Map two pairs of coordinates (ZZ(0),ZZ(1)) and (ZZ(2),ZZ(3)) onto screen window as (WW(0),WW(1)) and (WW(2),WW(3)).

90 REPEAT FOR I%=0TO3:ZZ%(I%)=ZZ%(I%)+VV%(I%)
100 WW%(I%)=ABS(ZZ%(I%)MOD(CC%(I%)*2)-CC%(I%))
110 NEXT
120 C%=C%MOD3+1:GCOL0,C%
130 MOVE WW%(0),WWS(1):PLOTG%,WW%(2),WW%(3)

Keep plotting an different colours until return to starting coordinates, than repeat in black to clear picture.

140 UNTIL WW%(0)=XX%(0) AND WW%(1)=XX%(1) AND WW%(2)=XX%(2) AND WW%(3)=XX%(3)
150 NEXT:UNTIL 0

Variables:

CC%(0)..CC%(3) - Screen coordinates
C% - Current colour 0-3
G% - Plotting code; G%=5 gives plottinq in white, and
G%=7 gives plotting in black
I - Index for arrays
VVS(0)..VV%(3) - Vectors by which the two balls move at each stage
WW%(0)..WW%(3) - Coordinates of two bouncing balls
XX%(0)..XX%(3) - Starting coordinates of balls
ZZ%(0)..ZZ%(3) - Coordinates of balls before mapping them to the screen; all positive

Atom Version

The Atom version uses the 256x192 graphics mode, and plots the lines in white.

10 REM ... PATTERNS ...
15 DIM XX3,ZZ3,VV3,CC3,WW3
20 DO CLEAR4
25 CC0=256;CC1=192;CC2=CC0;CC3=CC1
30 FOR I=0TO3;XXI=ABSRND;VVI=ABSRND%4*2
40 XXI=XXI%CCI;ZZI=XXI+CCI;NEXT
45 FOR G=5TO7 STEP2

Map two pairs of coordinates ZZ0,ZZ1 and (ZZ2,ZZ3) onto screen window as (WW0,WW1) and (WW2,WW3).

50 DO FOR I=0TO3;ZZI=ZZI+VVI 
55 WWI=ABS(ZZI%(CCI*2)-CCI) 
60 NEXT
65 MOVE WW0,WW1;PLOTG,WW2,WW3

Keep plotting in white until return to starting coordinates, then repeat in black to clear picture.

70 UNTIL WW0=XX0 AND WW1=XX1 AND WW2=XX2 AND WW3=XX3
90 NEXT;UNTIL 0

Variables:

CC0..CC3 - Screen coordinates
G - Plotting code; G=5 gives plotting in white, and G=7 gives plotting in black
I - Index for arrays
VV0..VV3 - Vectors by which the two balls move at each stage
WW0..WW3 - Coordinates of two bouncing balls
XX0..XX3 - Starting coordinates of balls
ZZ0..ZZ3 - Coordinates of balls before mapping them to the screen; all positive

Further Suggestions

A variant on these patterns can be obtained by replacing line 45 with:

45 FOR H%=0TO1;G%=6

or its equivalent on the Atom. The lines will then be drawn by inverting the screen.

The spacing of lines on the screen is determined by the values of VV%(0) to VV%(3) set in line 30. In the versions given above these values are constrained to be even, to limit the life of each pattern, but this can be altered to vary the spacing.