Refactor draw logic for use in running mode
authorJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:17:31 +0000 (20:17 -0500)
committerJC <dev@jacobcasper.com>
Mon, 31 Jul 2023 01:18:04 +0000 (20:18 -0500)
source/main.lua

index 7bb6ef3..ee91d8d 100644 (file)
@@ -18,24 +18,27 @@ local y = 1
 
 local running = false
 
+function draw(cells)
+    for i,row in ipairs(cells) do
+        for j,r in ipairs(row) do
+            if r.live then
+                gfx.setColor(gfx.kColorBlack)
+            else
+                gfx.setColor(gfx.kColorWhite)
+            end
+
+            gfx.fillRect(r.cell)
+            gfx.setColor(gfx.kColorBlack)
+            gfx.drawRect(r.cell)
+
+        end
+    end
+end
 
 function playdate.update()
     if not running then
         -- automata state setup
-        for i,row in ipairs(cells) do
-            for j,r in ipairs(row) do
-                if r.live then
-                    gfx.setColor(gfx.kColorBlack)
-                else
-                    gfx.setColor(gfx.kColorWhite)
-                end
-
-                gfx.fillRect(r.cell)
-                gfx.setColor(gfx.kColorBlack)
-                gfx.drawRect(r.cell)
-
-            end
-        end
+        draw(cells)
 
         if playdate.buttonJustPressed("right") then
             x = math.min(WIDTH, x + 1)
@@ -52,5 +55,6 @@ function playdate.update()
         end
     else
         -- running
+        draw(cells)
     end
 end