The Ultimate Chaos Game
- Type
- Graphics
- Category
- Fractals by random iteration (the Chaos Game)
- Author
- Roger A. Pruitt
- Published in
- Antic, December 1989/January 1990 (Vol. 8, No. 7)
- Year
- 1989
- Language
- Atari BASIC
- Requirements
- 48K RAM, Atari BASIC, disk drive (Ultimate Chaos Game); any Atari 8-bit for the short demo; Epson-compatible printer optional
About the program
Roger Pruitt was a professor of physics at Fort Hays State University in Kansas, where his department used eight Atari 8-bit computers for student work and laboratory data collection. In this article he introduced Antic readers to "chaos", which he described as the new science of deterministic disorder. It takes in fractal shapes such as coastlines, clouds and tree bark, which show more detail the closer you look. He then described a surprising way to draw one. The usual Sierpinski gasket is made by repeatedly cutting the middle out of a triangle. Michael Barnsley of the Georgia Institute of Technology found you can grow the same shape from random moves, a process he called the Chaos Game:
- Mark the three corners of a triangle and start at any point.
- Pick a corner at random and move halfway towards it. Plot a dot there.
- Repeat.
At first the dots seem scattered at random. Then the gasket's nested triangles appear, as Pruitt put it, order emerging from chaos.
There are two listings. GASKET.BAS (11 lines) is exactly the recipe above. CHAOS.BAS, The Ultimate Chaos Game, generalises it to any polygon from 1 to 10 sides (fractions allowed) and any scale factor, and adds printing and saving.
Typing it in
GASKET.BAS is plain text. In CHAOS.BAS, lines 28360–28370 (a machine-language screen-to-printer converter) and 28400–28410 (save and load routines) are strings full of inverse and control characters. The magazine offered a third listing to write them to LINES.LST for merging, and the disk version printed here already includes them. {inv}…{/inv} means type with the Atari (inverse) key on, {CTRL-E} means hold CTRL and press E, and {INS LINE} is ESC followed by SHIFT-INSERT. The menu frame in lines 10010–10030 uses CTRL-Q, CTRL-R, CTRL-Z and similar box-drawing characters.
How to use it
GASKET.BAS: just RUN it and wait. The gasket comes into focus over the first few minutes.
CHAOS.BAS: choose 1 to create a pattern. Give a picture name (up to 8 letters, and .PIC is added for you), the number of sides, and a scale factor greater than 0 and no more than 1. Then press START. Three sides and a scale of 0.5 reproduce the gasket. Pruitt noted that smaller scales (such as .333) give smaller, separate clusters at each corner, values above .5 start to overlap and fill in, and 1 plots every point on top of the last. Try five or six sides with scales around .35–.4. While it draws:
- SELECT saves the picture in Micro-Painter format (it needs 62 free sectors).
- OPTION prints it on an Epson-compatible printer.
- Hold START and press OPTION to go back to the menu.
Menu option 2 loads a saved picture by name.
How it works
In GASKET.BAS each move is a single line: X1=(Xcorner+X0)/2 is halfway to the chosen corner. CHAOS.BAS places P corners evenly around a circle (lines 1040–1070, using DEG and SIN/COS) and generalises "halfway" to a scale factor S. Line 1060 pre-computes each corner's position so that the main loop (lines 1090–1110) only needs one multiplication per coordinate. The program reads the console keys directly from 53279 inside the drawing loop, so it never stops to wait for input. The save routine writes the whole 7,680-byte screen in one CIO call, through a string-based USR routine.
Variations to try
- Give the corners unequal chances. In GASKET.BAS, pick corner 1 twice as often (
I=INT(4*RND(0)+1)and treat 4 as 1) and watch the gasket become lopsided. - In the Ultimate program, try 4 sides with a scale of 0.5. Unlike the triangle, the square just fills in solid. Not every polygon and scale makes a fractal.
Listings
GASKET.BAS, the short demonstration:
1 REM CHAOS GAME DEMONSTRATION
2 REM BY ROGER A. PRUITT
3 REM (C) 1989 ANTIC PUBLISHING, INC
100 GRAPHICS 24:SETCOLOR 2,0,0:SETCOLOR 1,0,10:COLOR 1
110 X0=INT(250*RND(0)):Y0=INT(150*RND(0))
120 I=INT(3*RND(0)+1)
130 IF I=1 THEN X1=X0/2:Y1=Y0/2
140 IF I=2 THEN X1=(318+X0)/2:Y1=Y0/2
150 IF I=3 THEN X1=(159+X0)/2:Y1=(191+Y0)/2
160 PLOT X1,Y1:X0=X1:Y0=Y1
170 GOTO 120
CHAOS.BAS, The Ultimate Chaos Game:
1000 REM THE ULTIMATE CHAOS GAME!
1001 REM BY ROGER A. PRUITT
1002 REM (C) ANTIC PUBLISHING, INC
1010 GOSUB 28350:GOTO 10000
1030 GRAPHICS 24:SETCOLOR 2,0,0:SETCOLOR 1,0,10:COLOR 1
1040 CX=318/2:CY=190/2:DEG :I=1:SIZE=360/P
1050 FOR TH=0 TO 360 STEP SIZE:X=CX+CY*SIN(TH):Y=CY-CY*COS(TH)
1060 X(I)=-X+X/S:Y(I)=-Y+Y/S
1070 I=I+1:NEXT TH
1080 X0=INT(320*RND(0)):Y0=INT(192*RND(0))
1090 I=INT(P*RND(0)+1)
1100 X1=(X(I)+X0)*S:Y1=(Y(I)+Y0)*S
1110 PLOT X1,Y1:X0=X1:Y0=Y1
1120 IF PEEK(53279)=2 THEN 10000
1130 IF PEEK(53279)=3 THEN GOSUB 3000
1140 IF PEEK(53279)=5 THEN GOSUB 5000
1160 GOTO 1090
3000 TRAP 4000:CLOSE #1:OPEN #1,8,0,"P:":? #1;CHR$(27);"C";CHR$(0);CHR$(11);
3010 ? #1;CHR$(27);"D";CHR$(8);CHR$(16);CHR$(24);CHR$(32);CHR$(40);CHR$(48);CHR$(56);CHR$(64);CHR$(72);CHR$(0)
3020 DM=PEEK(88)+PEEK(89)*256
3030 PRINT #1;CHR$(27);"A";CHR$(8)
3100 FOR I=0 TO 23:XX=DM+320*I
3110 A$=CHR$(0):A$(320)=CHR$(0):A$(2)=A$
3120 W=USR(ADR(RSD$),XX,ADR(A$)):PRINT #1;"{inv}{CTRL-I}{CTRL-I}{/inv}";CHR$(27);"K";CHR$(64);CHR$(1);A$:NEXT I:? #1;CHR$(27);"@"
3130 POKE 764,255
3140 RETURN
4000 IF PEEK(53279)=3 THEN TRAP 40000:GOTO 3000
4010 GOTO 4000
5000 B$(1)="D:":B$(LEN(B$)+1)=NAME$:B$(LEN(B$)+1)=".PIC"
5010 SCREEN=PEEK(88)+256*PEEK(89)
5020 TRAP 5040:CLOSE #2:OPEN #2,IO,0,B$
5030 W=USR(ADR(DUMMY$),2,SCREEN,7680):CLOSE #2:RETURN
5040 CLOSE #2:TRAP 40000:POP
5050 ? :POSITION 14,12:? "DISK ERROR.":FOR X=1 TO 400:NEXT X:GOTO 10000
6000 GRAPHICS 24:SETCOLOR 2,0,0:SETCOLOR 1,0,10
6010 GOSUB 5000
6020 IF PEEK(53279)=2 THEN 10000
6030 IF PEEK(53279)=3 THEN GOSUB 3000
6040 GOTO 6020
10000 GRAPHICS 0:POKE 752,1
10010 POSITION 7,2:? "{CTRL-Q}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-E}"
10020 POSITION 7,3:? "|THE ULTIMATE CHAOS GAME!|":POSITION 7,4:? "| by Roger A. Pruitt |"
10030 POSITION 7,5:? "{CTRL-Z}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-R}{CTRL-C}"
10040 POSITION 12,8:? "1. Create Chaos."
10050 POSITION 12,10:? "2. Load Picture."
10060 POSITION 3,13:? "Select option by pressing 1 or 2.";
10070 POKE 764,255:POKE 694,0:POKE 702,64:GET #3,K:IF K<49 OR K>50 THEN 10070
10080 FOR I=0 TO 15:POSITION 2,8:? "{DEL LINE}":NEXT I
10090 POSITION 2,8:? "Input picture name";:INPUT NAME$
10100 IF K=50 THEN IO=4:DUMMY$=LDR$:GOTO 6000
10110 IO=8:DUMMY$=SVR$
10140 TRAP 10140:POSITION 2,10:? "Give number of sides of polygon":INPUT P:IF P<1 THEN P=1
10145 IF P>10 THEN POSITION 3,11:? " ":GOTO 10140
10150 TRAP 10150:POSITION 2,13:? "Give scale factor ( >0 TO 1 )":INPUT S
10155 IF (S<=0) OR (S>1) THEN POSITION 3,14:? " ":GOTO 10150
10156 TRAP 40000
10160 POKE 752,1:POSITION 6,18:? "To print press{CTRL-B}{inv}OPTION{/inv}{CTRL-V}key."
10170 POSITION 3,19:? "To save to disk press{CTRL-B}{inv}SELECT{/inv}{CTRL-V}key."
10180 POSITION 2,20:? "To quit hold{CTRL-B}{inv}START{/inv}{CTRL-V}and press{CTRL-B}{inv}OPTION{/inv}."
10190 POSITION 4,23:? "To create CHAOS press{CTRL-B}{inv}START{/inv}{CTRL-V}key.";
10200 IF PEEK(53279)=6 THEN GOTO 1030
10210 GOTO 10200
28350 DIM RSD$(103),A$(640),NAME$(8),B$(14),SVR$(39),LDR$(39),DUMMY$(39),X(11),Y(11)
28360 RSD$(1)="hh{inv}{CTRL-E}Q{CTRL-E}U{/inv}h{inv}{CTRL-E}P{CTRL-E}T{/inv}h{inv}{CTRL-E}O{/inv}h{inv}{CTRL-E}N){/inv}{CTRL-,}{inv}{CTRL-E}M"{/inv}{CTRL-,}{inv} {/inv}{CTRL-,}{inv}1T{CTRL-U}V{/inv}{CTRL-X}{inv}%T{/inv}i({inv}{CTRL-E}T{CTRL-P}{/inv}{CTRL-B}{inv}fUh{CTRL-.}{/inv}{CTRL-H}{inv}Pj {/inv}{CTRL-,}{inv}"{/inv}{CTRL-,}{CTRL-V}{inv}V1N{/inv}*{inv}{CTRL-Q}Nh{CTRL-.}{/inv}{CTRL-H}{inv}PtH@{/inv}{CTRL-H}{inv}Pm{/inv}{CTRL-X}{inv}%N{/inv}i{CTRL-H}{inv}{CTRL-E}N{CTRL-P}{/inv}{CTRL-B}{inv}fO{/inv}{CTRL-X}{inv}%P{/inv}i{CTRL-A}{inv}{CTRL-E}P{CTRL-E}T{CTRL-P}{/inv}{CTRL-B}{inv}fQ{/inv}"
28370 RSD$(91)="{inv}%Q{CTRL-E}UfM%MI{/inv}({inv}P/{/inv}{CTRL-.}"
28380 CLOSE #3:OPEN #3,4,0,"K:"
28400 LDR$="hhh{CTRL-J}{CTRL-J}{CTRL-J}{CTRL-J}{inv}*){/inv}{CTRL-G}{INS LINE}B{CTRL-C}h{INS LINE}E{CTRL-C}h{INS LINE}D{CTRL-C}h{INS LINE}I{CTRL-C}h{INS LINE}H{CTRL-C} V{inv}d{CTRL-D}T {/inv}{CTRL-,}{inv}{CTRL-D}U{/inv}{CTRL-.}"
28410 SVR$="hhh{CTRL-J}{CTRL-J}{CTRL-J}{CTRL-J}{inv}*){/inv}{CTRL-K}{INS LINE}B{CTRL-C}h{INS LINE}E{CTRL-C}h{INS LINE}D{CTRL-C}h{INS LINE}I{CTRL-C}h{INS LINE}H{CTRL-C} V{inv}d{CTRL-D}T {/inv}{CTRL-,}{inv}{CTRL-D}U{/inv}{CTRL-.}"
28430 RETURN
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: CHAOS.BAS, GASKET.BAS.
Credits
- Program listing: The Ultimate Chaos Game — program listing (Antic, December 1989/January 1990 (Vol. 8, No. 7)) — Roger A. Pruitt
- Picture: The Ultimate Chaos Game with 5 sides and a scale of 0.375, a minute after starting. — Roger A. Pruitt (program); screenshot by the site
- Antic Software Archive — December 1989/January 1990 - Vol. 8 No. 7 disk: CHAOS.BAS — Roger A. Pruitt, 1989
- Antic Software Archive — December 1989/January 1990 - Vol. 8 No. 7 disk: GASKET.BAS — AtariMagazines.com (Kevin Savetz), 1989
- Antic magazine scan (OCR text layer): Antic_Vol_8-07_1989-12_Seeing_Sounds_text.pdf — Internet Archive
