10 CLEAR ALL
20 SCREEN LOAD "IMG_7432.JPG"
30 SLEEP
40 CONST W=800
50 CONST H=400
60 SCREEN BITMAP W,H
70 CONST T=2 '=8
80 WIDTH=INT(W/T)
90 HEIGHT=INT(H/T)
100 DIM current(WIDTH),nextLine(WIDTH)
110 READ ruleNum:IF ruleNum=-1 THEN END
120 GOSUB 160
130 GOTO 110
140 DATA 30,182,60
150 DATA -1
160 RANDOMIZE TIMER
170 FOR i=0 TO 7
180     rule(i)=ruleNum AND 1
190     ruleNum=INT(ruleNum/2)
200 NEXT i
210 FOR i=0 TO WIDTH
220     current(i)=0
230 NEXT i
240 current(INT(WIDTH/2))=1
250 CLEAR BITMAP
260 FOR y=0 TO HEIGHT
270     FOR x=0 TO WIDTH
280         IF current(x)=1 THEN
290             INK RGB(255,255,255)
300             RECT FILL T*x,T*y,T*x+T-1,T*y+T-1
310         END IF
320         IF x>0 AND x<WIDTH-1 THEN
330             l=current(x-1)
340             c=current(x)
350             r=current(x+1)
360             index=4*l+2*c+r
370             nextLine(x)=rule(index)
380         END IF
390     NEXT x
400     FOR i=0 TO WIDTH
410         current(i)=nextLine(i)
420     NEXT i
430 NEXT y
440 SLEEP
450 RETURN
