Conway's Game of Life: Difference between revisions
Content deleted Content added
Added another D version |
No edit summary |
||
Line 2,214: | Line 2,214: | ||
[[File:Blinker.gif]] |
[[File:Blinker.gif]] |
||
=={{header|Liberty BASIC}}== |
|||
It will run slow for grids above say 25! |
|||
<lang lb> |
|||
nomainwin |
|||
gridX = 20 |
|||
gridY = gridX |
|||
mult =500 /gridX |
|||
pointSize =360 /gridX |
|||
dim old( gridX +1, gridY +1), new( gridX +1, gridY +1) |
|||
'Set blinker: |
|||
old( 16, 16) =1: old( 16, 17) =1 : old( 16, 18) =1 |
|||
'Set glider: |
|||
old( 5, 7) =1: old( 6, 7) =1: old( 7, 7) =1 |
|||
old( 7, 6) =1: old( 6, 5) =1 |
|||
WindowWidth =570 |
|||
WindowHeight =600 |
|||
open "Conway's 'Game of Life'." for graphics_nsb_nf as #w |
|||
#w "trapclose [quit]" |
|||
#w "down ; size "; pointSize |
|||
#w "fill black" |
|||
'Draw initial grid |
|||
for x = 1 to gridX |
|||
for y = 1 to gridY |
|||
'#w "color "; int( old( x, y) *256); " 0 255" |
|||
if old( x, y) <>0 then #w "color red" else #w "color darkgray" |
|||
#w "set "; x *mult +20; " "; y *mult +20 |
|||
next y |
|||
next x |
|||
' ______________________________________________________________________________ |
|||
'Run |
|||
do |
|||
for x =1 to gridX |
|||
for y =1 to gridY |
|||
'find number of live Moore neighbours |
|||
neighbours =old( x -1, y -1) +old( x, y -1) +old( x +1, y -1)+_ |
|||
old( x -1, y) +old( x +1, y )+_ |
|||
old( x -1, y +1) +old( x, y +1) +old( x +1, y +1) |
|||
was =old( x, y) |
|||
if was =0 then |
|||
if neighbours =3 then N =1 else N =0 |
|||
else |
|||
if neighbours =3 or neighbours =2 then N =1 else N =0 |
|||
end if |
|||
new( x, y) = N |
|||
'#w "color "; int( N /8 *256); " 0 255" |
|||
if N <>0 then #w "color red" else #w "color darkgray" |
|||
#w "set "; x *mult +20; " "; y *mult +20 |
|||
next y |
|||
next x |
|||
scan |
|||
'swap |
|||
for x =1 to gridX |
|||
for y =1 to gridY |
|||
old( x, y) =new( x, y) |
|||
next y |
|||
next x |
|||
'Re-run until interrupted... |
|||
loop until FALSE |
|||
'User shutdown received |
|||
[quit] |
|||
close #w |
|||
end |
|||
</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
<lang lua>function Evolve( cell ) |
<lang lua>function Evolve( cell ) |