2 local btui = require("btui")
7 local function draw(bt, cells)
10 local alive = cells[x][y]
11 local key = tostring(x)..","..tostring(y)
12 if screen[key] ~= alive then
14 bt:withbg(alive, alive, alive, function()
23 local function get(cells, x, y)
29 local function count_neighbors(cells, x, y)
33 if dx ~= 0 or dy ~= 0 then
34 n = n + get(cells, x+dx, y+dy)
41 local function update(cells)
46 local n = count_neighbors(cells, x, y)
47 if (get(cells, x, y) == 0 and n == 3) or (get(cells, x, y) == 1 and (n == 2 or n == 3)) then
71 while key ~= "q" and key ~= "Ctrl-c" do
77 local mouse_x, mouse_y
78 key, mouse_x, mouse_y = bt:getkey(1)
79 if mouse_x and mouse_y then
80 cells[math.floor(mouse_x/2)][mouse_y] = 1
86 if key == "Ctrl-c" then
87 error("Interrupt received!")