Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,57 @@
|
|||
// Conway's Game of Life
|
||||
clear
|
||||
rows = 64; rowRange = range(0, rows-1)
|
||||
cols = 96; colRange = range(0, cols-1)
|
||||
// prepare two tile displays, in display layers 4 and 5
|
||||
img = Image.create(2, 1); img.setPixel 1, 0, color.white
|
||||
grids = []
|
||||
for dispIdx in [4,5]
|
||||
display(dispIdx).mode = displayMode.tile
|
||||
td = display(dispIdx)
|
||||
td.cellSize = 10 // size of cells on screen
|
||||
td.extent = [cols, rows]
|
||||
td.overlap = -1 // adds a small gap between cells
|
||||
td.tileSet = img; td.tileSetTileSize = 1
|
||||
td.clear 0
|
||||
grids.push td
|
||||
end for
|
||||
|
||||
// initialize to a random state
|
||||
for x in colRange
|
||||
for y in rowRange
|
||||
td.setCell x, y, rnd > 0.5
|
||||
end for
|
||||
end for
|
||||
|
||||
curIdx = 5
|
||||
// main loop
|
||||
while true
|
||||
yield
|
||||
td = grids[curIdx-4]
|
||||
newIdx = 4 + (curIdx == 4)
|
||||
newTd = grids[newIdx-4]
|
||||
for x in colRange
|
||||
for y in rowRange
|
||||
// get sum of neighboring states
|
||||
sum = 0
|
||||
for i in [x-1, x, x+1]
|
||||
if i < 0 or i >= cols then continue
|
||||
for j in [y-1, y, y+1]
|
||||
if j < 0 or j >= rows then continue
|
||||
if i==x and j==y then continue
|
||||
sum = sum + td.cell(i,j)
|
||||
end for
|
||||
end for
|
||||
// Now, update the cell based on current state
|
||||
// and neighboring sum.
|
||||
if td.cell(x,y) then
|
||||
newTd.setCell x, y, (sum == 2 or sum == 3)
|
||||
else
|
||||
newTd.setCell x, y, sum == 3
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
display(newIdx).mode = displayMode.tile
|
||||
display(curIdx).mode = displayMode.off
|
||||
curIdx = newIdx
|
||||
end while
|
||||
Loading…
Add table
Add a link
Reference in a new issue