Try to track the levels this psychedelic CA machine traverses before returning to its initial state:

'Subject: A cellular automaton kaleidoscope.

' You'll find the full version of this fascinating

' Fredkin fractal machine in the Grids.zip-package at

' http://home.graffiti.net/vspickelen:graffiti.net/index.html

'Author : vspickelen

'Date : 02-08-2006

'Code : all Q-Basic's, FreeBasic extendable

'Keys : [Esc] quit program

' Any other key to restart

DEFINT A-Z

CONST TMX = .2 ' set delay in s.

CONST MODE = 12, dW = 640, dH = 480

' set screenmode, width, height

'CONST MODE = 20, dW = 1024, dH = 768 ' FreeBasic only

CONST MAX = 256 ' * Must be a power-of-two! *

' (unless you wanta freaked out machine)

' Maximum grid size is 128 for Q-Basic's

CONST n1 = MAX - 1

SCREEN MODE

PALETTE 0, &H40406: PALETTE 1, &H70F00

PALETTE 2, &HA0009: PALETTE 3, &H121E

r = (dW - dH) \ 2

VIEW (r, 1)-(dW - r, dH - 2), , 3

WINDOW SCREEN (-.5, -.5)-(n1 + .5, n1 + .5)

RANDOMIZE TIMER

sw = 0

begin:

REDIM c(n1, n1, 1)

x = n1 \ 2

y = 1 + INT(RND * x)

FOR r = x - y TO x + y

FOR s = x - y TO x + y

c(s, r, sw) = 1

NEXT s

NEXT r

CLS : RR = INT(RND * 2)

DO

dt! = TIMER

FOR r = 0 TO n1

FOR s = 0 TO n1

t = 0: IF RR THEN t = -c(s, r, sw)

FOR rn = r - 1 TO r + 1

ds = 1 - ABS(rn - r)

FOR sn = s - ds TO s + ds

x = (sn + MAX) AND n1

y = (rn + MAX) AND n1

t = t + c(x, y, sw)

NEXT sn

NEXT rn

IF RR THEN t = t XOR c(s, r, 1 - sw)

i = c(s, r, sw) * 2 AND 2

c(s, r, 1 - sw) = i OR (t AND 1)

NEXT s

NEXT r

sw = 1 - sw

d! = .491

FOR y = 0 TO n1

FOR x = 0 TO n1

IF c(x, y, sw) XOR c(x, y, 1 - sw) THEN

LINE (x - d!, y - d!)-(x + d!, y + d!), c(x, y, sw), BF

END IF

NEXT x

NEXT y

g$ = INKEY$

IF g$ <> "" THEN

IF ASC(g$) = 27 THEN

EXIT DO

ELSE

GOTO begin

END IF

WHILE INKEY$ <> "": WEND

END IF

WHILE TMX > TIMER - dt!: WEND

LOOP

SYSTEM

-You'll soon lose count.

vspickelen