Add function to calculate next generation
authorJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:29:53 +0000 (20:29 -0500)
committerJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:29:53 +0000 (20:29 -0500)
Right now it simply flips bits instead of checking neighbors

source/main.lua

index ee91d8d..ce2c572 100644 (file)
@@ -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