From: JC Date: Mon, 31 Jul 2023 01:17:31 +0000 (-0500) Subject: Refactor draw logic for use in running mode X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=2564bbe2074c0a4eccf616fadbae3b01ea09093f;p=life-pd.git Refactor draw logic for use in running mode --- 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