It behaves like it should ...
Just a bit modified your code...
Just a bit modified your code...
Const gw=800 Const gh=600 Graphics gw,gh,0,2 SetBuffer BackBuffer() Dim pixel(gw,gh) SeedRnd(MilliSecs()) For x=gw/4 To (gw-gw/4) For y=gh/4 To (gh-gh/4) temp=Rand(-30,1) If temp<0 pixel(x,y)=0 Else pixel(x,y)=temp EndIf Next Next Delay 2000 While Not KeyDown(1) Cls SeedRnd(MilliSecs()) LockBuffer BackBuffer() For y=1 To gh-2 For x=1 To gw-2 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)=0 And (neibors=3); Or neibors=6) pixel(x,y)=1 Else If pixel(x,y)=1 And (neibors=2 Or neibors=3) pixel(x,y)=1 Else pixel(x,y)=0 EndIf If pixel(x,y)=1 Then WritePixelFast x,y,$ffffffff If pixel(x,y)=0 Then WritePixelFast x,y,$ff000000 Next Next UnlockBuffer() Delay 1 If KeyDown(57) Then Delay 500 Flip Wend End