Chaos

Developer(s): Michael Carver
Date: 1989
Type: Diskette
Platform(s): QL
Tags: Graphics

The chaos game on the Sinclair QL: from a corner of a triangle, it plots point after point, each halfway towards a randomly chosen corner, in random colours. Instead of filling the triangle, the points build up a Sierpinski triangle.

LRUN it, read the introduction and press a key; ESC stops it. The author says it was inspired by a NOVA programme. The editor printed a note that his copy drew only a diagonal line and that he could not find the error.

Published in The Plotter April 1989 (Chaos).

Source Code

10 REMark *** Chaos by Michael E. Carver
20 REMark *** 2/11/89
30  chaos
100 DEFine PROCedure chaos
105   introduction
110   RANDOMISE
115   CLS #4
117   message
120   REMark *** select starting point
130   n=RND(1 TO 6)
135   INK #4,n+1
140   SELect ON n
150    ON n=1 TO 2: x=0: y=255
160    ON n=3 TO 4: x=255: y=255
170    ON n=5 TO 6: x=127: y=0
180   END SELect
190   the_show
210 END DEFine chaos
220 :
230 DEFine PROCedure choose
240   n=RND(1 TO 6)
260 END DEFine choose
270 :
280 DEFine PROCedure where
290   SELect ON n
300    ON n=1 TO 2: x=dec(x): y=inc(y)
400    ON n=3 TO 4: x=inc(x): y=inc(y)
500    ON n=5 TO 6
502     SELect ON x
510      ON x=128 TO 255: x=mid_dec(x)
515      ON x=0 TO 126: x=mid_inc(x)
517     END SELect
520     y=dec(y)
600    END SELect
610 END DEFine where
620 :
630 DEFine PROCedure display
640   POINT #4,x,y
645   INK #4,RND(2 TO 7)
650 END DEFine display
660 :
670 DEFine PROCedure the_show
680   REPeat loop
690    choose
695    where
700    display
705    IF INKEY$=CHR$(27) THEN STOP
710   END REPeat loop
720 END DEFine the_show
730 :
740 DEFine FuNction dec(a)
755   a=a/2
760   RETurn a
770 END DEFine dec
780 :
790 DEFine FuNction inc(a)
800   a=a+(256-a)/2
810   RETurn a
820 END DEFine inc
830 :
840 DEFine FuNction mid_dec(a)
850   a=a-(a-127)/2
860   RETurn a
870 END DEFine mid_dec
880 :
890 DEFine FuNction mid_inc(a)
900   a=a+(127-a)/2
910   RETurn a
920 END DEFine mid_inc
930 :
940 DEFine PROCedure introduction
950   canvas
960   CSIZE #4,3,1: INK #4,43
970   AT #4,1,10: PRINT #4,"C H A O S"
980   CSIZE #4,1,0: INK #4,6
990   PRINT #4,\"The following program will illustrate an amazing concept of"\"CHAOS."
1000   PRINT #4\\"Imagine a triangle standing on its point.  The upper left-hand"\"corner is 1&2 -- the upper right-hand corner is 3&4 -- while the"\"bottom is 5&6."
1010   PRINT #4\\"The computer will pick a random number between 1 and 6 and will"\"plot a point within the triangle mid-way between the last point plotted and the corner equal to that number."
1020   PRINT #4\\"One would assume that the triangle would eventually be a solid  mass of points.  However CHAOS provides us with an interesting  result!"
1030   PRINT #4\\"Press any key to view the world of CHAOS for yourself. . ."
1040  PAUSE
1050 END DEFine introduction
1060 :
1070 DEFine PROCedure message
1075   STRIP #0,24
1080   PRINT #0;"ESC to quit"
1090   STRIP #0,0
1100 END DEFine message
1110 :
31900 DEFine PROCedure canvas
31902   MODE 4: OPEN #4,scr_512x256a0x0
31903   SCALE #4,256,-32,0
31904   PAPER #4,0: INK #4,6: CLS #4
31918 END DEFine canvas

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