Code: Select all
' "Automaton"
' simple version of earlier Automaton program
' runs on iPhones as well (tested on 3GS and 5S)
'
option base 0
sw=screen_width() ! sh=screen_height()
nw=sw/3-2 ! nh=(sh-80)/3
dim p1(nw+2),p2(nw+2),r(10)
randomize
graphics
graphics clear .8,.8,.8
draw color 0,0,.6
button "nex" title "next" at 10,sh-50 size 120,40
button "paus" title "hold" at 150,sh-50 size 120,40
loop1:
for i=0 to 9 ! r(i)=rnd(4) ! next i
for i=1 to nw ! p1(i)=rnd(4) ! next i
fill color .8,.8,.8 ! fill rect 0,0 to 200,20
draw text "rule:" at 2,0
for i=0 to 9 ! draw text r(i) at 62+12*i,0 ! next i
loop2:
y=20 ! ' disp(p1,y,nw)
for k=1 to nh/2
for i=1 to nw
p2(i)=p1(i-1)+p1(i)+p1(i+1) ! p2(i)=r(p2(i))
next i
y=y+3 ! disp(p2,y,nw)
for i=1 to nw
p1(i)=p2(i-1)+p2(i)+p2(i+1) ! p1(i)=r(p1(i))
next i
y=y+3 ! disp(p1,y,nw)
if button_pressed("nex") then goto loop1
if button_pressed("paus") then
button "paus" set title "continue"
loop3: if button_pressed("paus")=0 then goto loop3
button "paus" set title "hold"
end if
next k
goto loop2
end
def disp(p(),y,mat)
xp=0
graphics lock
for i=1 to mat
x=p(i)
if x=0 then
fill color 0,0,0
else
if x=1 then
fill color 1,0,0
else
if x=2 then
fill color 0,1,0
else
fill color 0,0,1
end if
end if
end if
xp=xp+3
fill rect xp,y to xp+3,y+3
next i
graphics unlock
end def