commit
[#ticker]
[#cell x: 1, y: 1, alive: false]
[#cell x: 2, y: 1, alive: false]
[#cell x: 3, y: 1, alive: false]
[#cell x: 1, y: 2, alive: true]
[#cell x: 2, y: 2, alive: true]
[#cell x: 3, y: 2, alive: true]
[#cell x: 1, y: 3, alive: false]
[#cell x: 2, y: 3, alive: false]
[#cell x: 3, y: 3, alive: false]
commit @browser
[#svg #grid, viewBox: "0 0 100 100", width: 200, height: 200, sort: 0]
[#div #ticker]
search @session @browser
grid = [#grid]
cell = [#cell, x, y]
color = if cell.alive = true then "#000" else "#fff"
bind @browser
grid.children += [#rect, x: 1+(x * 10), y: 1+(10 * y), width: 9, height: 9, fill: color]
search
[#time seconds]
ticker = [#ticker not(ready)]
commit
ticker += #ready
Update the game on the next tick.
Rules:
- Any live cell with fewer than two live neighbours dies, as if caused by under-population.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by over-population.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
search @session @browser
ticker = [#ticker #ready]
// find out how many alive neighbours each cell has
cell = [#cell]
neighbour = [#cell]
neighbour.x >= cell.x - 1
neighbour.x <= cell.x + 1
neighbour.y >= cell.y - 1
neighbour.y <= cell.y + 1
neighbour.alive = true
neighbour != cell
alive-neighbours = count[given: neighbour, per: cell]
// game rules
next-alive = if alive-neighbours < 2 then false
else if alive-neighbours > 3 then false
else if alive-neighbours = 2 then cell.alive
else if alive-neighbours = 3 then true
commit
ticker -= #ready
cell.alive := next-alive