From: JC Date: Mon, 31 Jul 2023 01:29:53 +0000 (-0500) Subject: Add function to calculate next generation X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=f613b92fe29737e2324362aa2ffd2ce1fdd2ebb1;p=life-pd.git Add function to calculate next generation Right now it simply flips bits instead of checking neighbors --- diff --git a/source/main.lua b/source/main.lua index ee91d8d..ce2c572 100644 --- a/source/main.lua +++ b/source/main.lua @@ -18,6 +18,17 @@ local y = 1 local running = false +function generation(cells) + local tab = {} + for i,row in ipairs(cells) do + tab[i] = {} + for j,cell in ipairs(row) do + tab[i][j] = { cell = cell.cell, live = not cell.live } + end + end + return tab +end + function draw(cells) for i,row in ipairs(cells) do for j,r in ipairs(row) do @@ -56,5 +67,6 @@ function playdate.update() else -- running draw(cells) + cells = generation(cells) end end