PROGRAM ca1! one-dimensional Boolean cellular automataDIM update(0 to 7),site(0 to 501)CALL setrule(update())CALL initial(site(),L,tmax,#2)CALL iterate(site(),L,update(),tmax,#2)ENDSUB setrule(update())    INPUT prompt "rule number = ": rule    OPEN #1: screen 0,0.5,0.2,0.8    SET BACKGROUND COLOR "black"    SET COLOR "white"    FOR i = 7 to 0 step -1        LET update(i) = int(rule/2^i)  ! find binary representation        LET rule = rule - update(i)*2^i        LET bit2 = int(i/4)        LET bit1 = int((i - 4*bit2)/2)        LET bit0 = i - 4*bit2 - 2*bit1        ! show possible neighborhoods        PRINT using "#": bit2,bit1,bit0;        PRINT "  ";    NEXT i    PRINT    FOR i = 7 to 0 step -1        PRINT using "##": update(i);   ! print rules        PRINT "   ";    NEXT i    CLOSE #1END SUBSUB initial(site(),L,tmax,#2)    RANDOMIZE    OPEN #2: screen 0.5,1,0.1,0.9    ASK PIXELS px,py    SET WINDOW 1,px,py,1    SET COLOR "yellow"    LET L = 2*int(px/8) - 8    LET tmax = L    LET site(L/2) = 1             ! center site    BOX AREA 1+2*L,2*L+4,1,4      ! each site 4 x 4 pixelsEND SUBSUB iterate(site(),L,update(),tmax,#2)    ! update lattice    ! need to introduce additional array, sitenew, to temporarily    ! store values of newly updated sites    DIM sitenew(0 to 501)    FOR t = 1 to tmax        FOR i = 1 to L            LET index = 4*site(i-1) + 2*site(i) + site(i+1)            LET sitenew(i) = update(index)            IF sitenew(i) = 1 then BOX AREA 1+i*4,i*4+4,1+t*4,t*4+4        NEXT i        MAT site = sitenew        LET site(0) = site(L)     ! periodic boundary conditions        LET site(L+1) = site(1)    NEXT tEND SUB