### Post by tkpatric on Jul 11, 2023 11:56:41 GMT -5

`nomainwin`

textbox #main.a, 6, 510, 400, 26

dim p(100,100)

dim pp(100,100)

WindowWidth = 522

WindowHeight = 576

open "LIFE" for graphics_nsb as #main

print #main, "fill palegray"

#main, "setfocus"

#main, "when rightButtonDown [start]"

#main, "when characterInput [clean]"

#main, "when leftButtonDown [punt]"

#main, "trapclose [quit]"

#main, "down"

#main.a," Leftbutton = place , Rightbutton = go on , Space = Clear "

gosub [clean]

FOR seedx=30 TO 45

FOR seedy=30 TO 45

if (rnd(0)*11)>7 then pp(seedx,seedy)=1

NEXT seedy

NEXT seedx

seedx=1:seedy=3: pp(seedx,seedy)=1

seedx=2:seedy=3: pp(seedx,seedy)=1

seedx=3:seedy=3: pp(seedx,seedy)=1

seedx=3:seedy=2: pp(seedx,seedy)=1

seedx=2:seedy=1: pp(seedx,seedy)=1

seedx=49:seedy=3: pp(seedx,seedy)=1

seedx=48:seedy=3: pp(seedx,seedy)=1

seedx=47:seedy=3: pp(seedx,seedy)=1

seedx=47:seedy=2: pp(seedx,seedy)=1

seedx=48:seedy=1: pp(seedx,seedy)=1

gosub [grid]:print #main, "flush"

#main, "size 5"

gosub [plotje]

'************************************************************

[start]

FOR x = 1 TO 50

FOR y = 1 to 50

neighbours = 0

IF p(x-1,y)=1 THEN neighbours = neighbours + 1

IF p(x+1,y)=1 THEN neighbours = neighbours + 1

IF p(x,y-1)=1 THEN neighbours = neighbours + 1

IF p(x,y+1)=1 THEN neighbours = neighbours + 1

IF p(x-1,y-1)=1 THEN neighbours = neighbours + 1

IF p(x+1,y-1)=1 THEN neighbours = neighbours + 1

IF p(x-1,y+1)=1 THEN neighbours = neighbours + 1

IF p(x+1,y+1)=1 THEN neighbours = neighbours + 1

' 3= born

IF p(x,y)=0 AND neighbours = 3 THEN pp(x,y)=1

' >3=Death <2=Death

IF p(x,y)=1 AND neighbours <2 THEN pp(x,y)=0

IF p(x,y)=1 AND neighbours >3 THEN pp(x,y)=0

' Neighbours 2 or 3 = it lives.

NEXT y

NEXT x

gosub [plotje]

goto [start]

'*************************************************************

[punt]

xx=int(MouseX/10+ .5): yy=int(MouseY/10+ .5)

p(xx,yy)=1: pp(xx,yy)=1

gosub [plotje]

wait

[clean]

FOR x=1 TO 50

FOR y=1 TO 50

pp(x,y)=0: p(x,y)=0

NEXT y

NEXT x

return

[plotje]

FOR x = 1 TO 50

FOR y = 1 to 50

scan

if pp(x,y)=0 then print #main, "color palegray"

if pp(x,y)=1 then print #main, "color blue"

print #main, "set ";x*10+1;" ";y*10+1

p(x,y)=pp(x,y)

NEXT y

NEXT x

print #main, "discard"

return

[grid]

print #main, "color black"

print #main, "size 1"

print #main, "place 0 0"

print #main, "down"

FOR n = 5 TO 505 STEP 10

print #main, "line "; n; " "; 5; " "; n; " "; 505

NEXT n

FOR n = 5 TO 505 STEP 10

print #main, "line "; 5; " "; n; " "; 505; " "; n

NEXT n

#main, "size 9"

print #main, "set ";251;" ";251

return

[quit]

close #main

end