Rem http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

fastgraphics

font "Arial", 20,100

graphsize 600,600

dim cell1(101,101)

dim cell2(101,101)

For x = 2 to 99

For y = 2 to 99

cell1[x,y]=int (rand*2)

next y

next x

for turn = 1 to 1000

For x = 2 to 99

For y = 2 to 99

neighbours = cell1[x-1,y]+cell1[x-1,y-1]+cell1[x,y-1]+cell1[x-1,y+1]+cell1[x+1,y-1]+cell1[x+1,y+1]+cell1[x,y+1]+cell1[x+1,y]

cell2[x,y]=cell1[x,y]

if cell1[x,y]=1 and (neighbours<2 or neighbours>3 ) then cell2[x,y]=0

if cell1[x,y]=0 and neighbours=3 then cell2[x,y]=1

next y

next x

For x = 2 to 99

For y = 2 to 99

cell1[x,y]=cell2[x,y]

color rgb( 255*(1-cell1[x,y]),255*(1-cell1[x,y]),255*(1-cell1[x,y]))

rect (6*x,6*y,6,6)

next y

next x

color red

text 10,10,"Cicle"+turn

refresh

next turn

## No comments:

## Post a Comment