Hi Group
I have revisited the code and this version is smaller and faster than the version above.
Of course it compiles to the same size.
I hope you enjoy the newer version.
; Conway's Game of Life
; Coded by Gary Barnes - The Control Key (June 2005)
; Smaller and faster than the previous version
Global w = 800
Global h = 600
Graphics w,h
SetBuffer BackBuffer()
Dim tG(w,h)
Dim nG(w,h)
h=h-1
w=w-1
SeedRnd MilliSecs()
Color 255,255,255
Plot 0,0
tcol = ReadPixel(0,0)
ClsColor 0,0,64
For y = 1 To H
For x = 1 To W
z = Rnd(1,10)
If z = 1 Then tG(x,y) = 1
Next
Next
Repeat
If Rnd(0,99) > 90 Then
rsx = Rnd(10,w-20)
rsy = Rnd(10,h-20)
For p = 0 To 9
rx = Rnd(rsx,rsx+5)
ry = Rnd(rsy,rsy+5)
tg(rx,ry) = 1
Next
EndIf
Cls
LockBuffer
For y = 1 To H
For x = 1 To W
sum = 0
sum = sum + tg(x-1,y-1) + tg(x,y-1) + tg(x+1,y-1) + tg(x-1,y) + tg(x+1,y) + tg(x-1,y+1) + tg(x,y+1) + tg(x+1,Y+1)
If sum = 2 Then ng(x,y) = tg(x,y)
If sum = 3 Then ng(x,y) = 1
If tg(x,y) > 0 Then WritePixelFast x,y,tcol
Next
Next
UnlockBuffer
Flip
For y = 1 To H
For x = 1 To W
tg(x,y) = ng(x,y)
Next
Next
Dim nG(w,h)
dummy = GetKey()
If dummy > 0 Then
If dummy = 32 Then WaitKey()
If dummy = 27 Then End
EndIf
Forever
End
I have revisited the code and this version is smaller and faster than the version above.
Of course it compiles to the same size.
I hope you enjoy the newer version.
; Conway's Game of Life
; Coded by Gary Barnes - The Control Key (June 2005)
; Smaller and faster than the previous version
Global w = 800
Global h = 600
Graphics w,h
SetBuffer BackBuffer()
Dim tG(w,h)
Dim nG(w,h)
h=h-1
w=w-1
SeedRnd MilliSecs()
Color 255,255,255
Plot 0,0
tcol = ReadPixel(0,0)
ClsColor 0,0,64
For y = 1 To H
For x = 1 To W
z = Rnd(1,10)
If z = 1 Then tG(x,y) = 1
Next
Next
Repeat
If Rnd(0,99) > 90 Then
rsx = Rnd(10,w-20)
rsy = Rnd(10,h-20)
For p = 0 To 9
rx = Rnd(rsx,rsx+5)
ry = Rnd(rsy,rsy+5)
tg(rx,ry) = 1
Next
EndIf
Cls
LockBuffer
For y = 1 To H
For x = 1 To W
sum = 0
sum = sum + tg(x-1,y-1) + tg(x,y-1) + tg(x+1,y-1) + tg(x-1,y) + tg(x+1,y) + tg(x-1,y+1) + tg(x,y+1) + tg(x+1,Y+1)
If sum = 2 Then ng(x,y) = tg(x,y)
If sum = 3 Then ng(x,y) = 1
If tg(x,y) > 0 Then WritePixelFast x,y,tcol
Next
Next
UnlockBuffer
Flip
For y = 1 To H
For x = 1 To W
tg(x,y) = ng(x,y)
Next
Next
Dim nG(w,h)
dummy = GetKey()
If dummy > 0 Then
If dummy = 32 Then WaitKey()
If dummy = 27 Then End
EndIf
Forever
End