From: JC Date: Mon, 31 Jul 2023 03:21:41 +0000 (-0500) Subject: Add ability to control generation rate via crank X-Git-Url: https://git.jacobcasper.com/?a=commitdiff_plain;h=40c65b47139a62bad75f661608686019b9ac9995;p=life-pd.git Add ability to control generation rate via crank This seems like a good idea --- diff --git a/source/main.lua b/source/main.lua index 889fa60..7394e3a 100644 --- a/source/main.lua +++ b/source/main.lua @@ -5,6 +5,21 @@ local WIDTH = 24 local HEIGHT = 14 local CELL_SIZE = 16 +--- refresh / generation rate during runtime +local refreshRate = 2 + +local INPUT_HANDLERS = { + cranked = function(change, acceleratedChange) + if change > 0 then + refreshRate = math.min(20, refreshRate + 1) + elseif change < 0 then + refreshRate = math.max(1, refreshRate - 1) + end + end +} + +pd.inputHandlers.push(INPUT_HANDLERS) + -- Convenience function for iterating over 8 neighbors function neighbors(g1, x, y) -- center tiles @@ -115,6 +130,7 @@ local x = 1 local y = 1 local running = false + function playdate.update() if playdate.buttonJustPressed("b") then running = not running @@ -138,7 +154,7 @@ function playdate.update() else -- running -- Make running less epileptic while letting interaction remain smooth - pd.display.setRefreshRate(2) + pd.display.setRefreshRate(refreshRate) draw(cells) cells = generation(cells) end