algorithmic art

Blitz3D Forums/Blitz3D Programming/algorithmic art

I was trying to make a cellular automata program, but none of my tests behaved the way other websites said they should. Do you know why? All the code looks right to me.
Const gw=80
Const gh=60
Graphics gw,gh,0,3
SetBuffer BackBuffer()

Dim pixel(gw,gh)
Dim pixel2(gw,gh)

SeedRnd(MilliSecs())
For x=0 To gw
	For y=0 To gh
		temp=Rand(0,1)+Rand(0,1)
		If temp<1 Then pixel(x,y)=1
	Next
Next

For x=0 To gw-1
	For y=0 To gh-1
		pixel2(x,y)=pixel(x,y)
	Next
Next

Delay 2000

While Not KeyDown(1)
LockBuffer BackBuffer()
For x=1 To gw-2
	For y=1 To gh-2
		If pixel2(x,y)=1 Then WritePixelFast x,y,-1
		If pixel2(x,y)=0 Then WritePixelFast x,y,$ff000000
		
		neibors=0
		If pixel(x+1,y+1)=1 Then neibors=neibors+1
		If pixel(x-1,y-1)=1 Then neibors=neibors+1
		If pixel(x+1,y-1)=1 Then neibors=neibors+1
		If pixel(x-1,y+1)=1 Then neibors=neibors+1
		If pixel(x,y+1)=1 Then neibors=neibors+1
		If pixel(x,y-1)=1 Then neibors=neibors+1
		If pixel(x+1,y)=1 Then neibors=neibors+1
		If pixel(x-1,y)=1 Then neibors=neibors+1
		
		If pixel(x,y)=1 And neibors<2 Then pixel2(x,y)=0
		If pixel(x,y)=1 And neibors>3 Then pixel2(x,y)=0
		If pixel(x,y)=0 And neibors=3 Then pixel2(x,y)=1
	Next
Next
For x=0 To gw-1
	For y=0 To gh-1
		pixel(x,y)=pixel2(x,y)
	Next
Next
UnlockBuffer()
If KeyDown(57) Then Delay 500
Flip
Wend
End