From 2564bbe2074c0a4eccf616fadbae3b01ea09093f Mon Sep 17 00:00:00 2001 From: JC Date: Sun, 30 Jul 2023 20:17:31 -0500 Subject: [PATCH] Refactor draw logic for use in running mode --- source/main.lua | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/source/main.lua b/source/main.lua index 7bb6ef3..ee91d8d 100644 --- a/source/main.lua +++ b/source/main.lua @@ -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 -- 2.20.1