Multiple steps per frame, set random seed

main
mat ess 2022-09-11 09:18:20 -04:00
parent 7cd25c4408
commit 31b3dec460
2 changed files with 32 additions and 27 deletions

View File

@ -31,6 +31,8 @@ end
local function initColors(rules) local function initColors(rules)
rules = rules:lower() rules = rules:lower()
local colorbrewer = require("colorbrewer") local colorbrewer = require("colorbrewer")
-- set a specific random seed to avoid picking the same palette every time
math.randomseed(os.time())
local scheme = colorbrewer.random() local scheme = colorbrewer.random()
local variant = scheme[#rules] local variant = scheme[#rules]
COLORS = {} COLORS = {}
@ -52,7 +54,6 @@ local function initScreen()
love.graphics.setColor(color) love.graphics.setColor(color)
love.graphics.rectangle("fill", 0, 0, WIDTH, HEIGHT) love.graphics.rectangle("fill", 0, 0, WIDTH, HEIGHT)
end) end)
UNITS = 8
end end
local function initAnt() local function initAnt()
@ -81,6 +82,8 @@ end
function love.load(args) function love.load(args)
local rules = args[1] or "RL" local rules = args[1] or "RL"
UNITS = args[2] or 8
STEPS_PER_FRAME = args[3] or 5
initColors(rules) initColors(rules)
initScreen() initScreen()
initAnt() initAnt()
@ -117,32 +120,34 @@ end
function love.update() function love.update()
require("lurker").update() require("lurker").update()
local c = nextColor() for _ = 1, STEPS_PER_FRAME do
ANT.direction = rotate(ANT.direction, c.clockwise) local c = nextColor()
CANVAS:renderTo(function() ANT.direction = rotate(ANT.direction, c.clockwise)
love.graphics.setBlendMode("alpha") CANVAS:renderTo(function()
love.graphics.setColor(c.rgba) love.graphics.setBlendMode("alpha")
love.graphics.rectangle("fill", ANT.x, ANT.y, UNITS, UNITS) love.graphics.setColor(c.rgba)
end) love.graphics.rectangle("fill", ANT.x, ANT.y, UNITS, UNITS)
if ANT.direction == "u" then end)
ANT.y = ANT.y - UNITS if ANT.direction == "u" then
elseif ANT.direction == "r" then ANT.y = ANT.y - UNITS
ANT.x = ANT.x + UNITS elseif ANT.direction == "r" then
elseif ANT.direction == "d" then ANT.x = ANT.x + UNITS
ANT.y = ANT.y + UNITS elseif ANT.direction == "d" then
else ANT.y = ANT.y + UNITS
ANT.x = ANT.x - UNITS else
end ANT.x = ANT.x - UNITS
end
if ANT.x >= WIDTH then if ANT.x >= WIDTH then
ANT.x = 0 ANT.x = 0
elseif ANT.x < 0 then elseif ANT.x < 0 then
ANT.x = (WIDTH - 1) - ((WIDTH - 1) % UNITS) ANT.x = (WIDTH - 1) - ((WIDTH - 1) % UNITS)
end end
if ANT.y >= HEIGHT then if ANT.y >= HEIGHT then
ANT.y = 0 ANT.y = 0
elseif ANT.y < 0 then elseif ANT.y < 0 then
ANT.y = (HEIGHT - 1) - ((HEIGHT - 1) % UNITS) ANT.y = (HEIGHT - 1) - ((HEIGHT - 1) % UNITS)
end
end end
end end

View File

@ -22,7 +22,7 @@
name = "love"; name = "love";
packages = [ love ]; packages = [ love ];
shellHook = '' shellHook = ''
mkdir vendor mkdir -p vendor
ln -snf ${lume}/lume.lua vendor/lume.lua ln -snf ${lume}/lume.lua vendor/lume.lua
ln -snf ${lurker}/lurker.lua vendor/lurker.lua ln -snf ${lurker}/lurker.lua vendor/lurker.lua
''; '';