From f613b92fe29737e2324362aa2ffd2ce1fdd2ebb1 Mon Sep 17 00:00:00 2001 From: JC Date: Sun, 30 Jul 2023 20:29:53 -0500 Subject: [PATCH] Add function to calculate next generation Right now it simply flips bits instead of checking neighbors --- source/main.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 -- 2.20.1