By the way, this code is short enough to run on the Lite/free version of Smart BASIC as well.
Code: Select all
REM Game of Life by h3ky1 2013
GRAPHICS ! RANDOMIZE ! s=10
maxx = INT(screen_width()/s)
maxy = INT(screen_height()/s)
DIM cello(maxx,maxy), celln(maxx,maxy)
FOR i=1 TO maxx*maxy*0.1
cello(RND(maxx),RND(maxy))=1
NEXT i
loop: ! g=g+1
GRAPHICS LOCK ! GRAPHICS CLEAR
FOR x=0 TO maxx-1
FOR y=0 TO maxy-1
IF cello(x,y)=1 THEN
FILL COLOR 1,0,0
FILL CIRCLE x*s,y*s SIZE s/2
END IF
NEXT y
NEXT x
t2=timer()
DRAW TEXT "G=" & STR$(g) & " T=" & STR$((t2-t1)/1000) AT 1,1
t1=timer()
GRAPHICS UNLOCK
FOR x=0 TO maxx-1
FOR y=0 TO maxy-1
n = 0
x0 = x-1
x1 = x+1
y0 = y-1
y1 = y+1
IF x0<0 THEN
x0=maxx-1
END IF
IF x1>maxx-1 THEN
x1=0
END IF
IF y0<0 THEN
y0=maxy-1
END IF
IF y1>maxy-1 THEN
y1=0
END IF
n=cello(x0,y0) + cello(x0,y) + cello(x0,y1) + cello(x,y0) + cello(x,y1) + cello(x1,y0) + cello(x1,y) + cello(x1,y1)
IF cello(x,y)=1 THEN
IF n<2 OR n>3 THEN
celln(x,y)=0
ELSE
celln(x,y)=1
END IF
END IF
IF cello(x,y)=0 THEN
IF n=3 THEN
celln(x,y)=1
ELSE
celln(x,y)=0
END IF
END IF
NEXT y
NEXT x
FOR x=0 TO maxx-1
FOR y=0 TO maxy-1
IF cello(x,y) <> celln(x,y) THEN
cello(x,y) = celln(x,y)
END IF
NEXT y
NEXT x
GOTO loop