Multiple steps per frame, set random seed
parent
7cd25c4408
commit
31b3dec460
|
@ -31,6 +31,8 @@ end
|
|||
local function initColors(rules)
|
||||
rules = rules:lower()
|
||||
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 variant = scheme[#rules]
|
||||
COLORS = {}
|
||||
|
@ -52,7 +54,6 @@ local function initScreen()
|
|||
love.graphics.setColor(color)
|
||||
love.graphics.rectangle("fill", 0, 0, WIDTH, HEIGHT)
|
||||
end)
|
||||
UNITS = 8
|
||||
end
|
||||
|
||||
local function initAnt()
|
||||
|
@ -81,6 +82,8 @@ end
|
|||
|
||||
function love.load(args)
|
||||
local rules = args[1] or "RL"
|
||||
UNITS = args[2] or 8
|
||||
STEPS_PER_FRAME = args[3] or 5
|
||||
initColors(rules)
|
||||
initScreen()
|
||||
initAnt()
|
||||
|
@ -117,32 +120,34 @@ end
|
|||
|
||||
function love.update()
|
||||
require("lurker").update()
|
||||
local c = nextColor()
|
||||
ANT.direction = rotate(ANT.direction, c.clockwise)
|
||||
CANVAS:renderTo(function()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setColor(c.rgba)
|
||||
love.graphics.rectangle("fill", ANT.x, ANT.y, UNITS, UNITS)
|
||||
end)
|
||||
if ANT.direction == "u" then
|
||||
ANT.y = ANT.y - UNITS
|
||||
elseif ANT.direction == "r" then
|
||||
ANT.x = ANT.x + UNITS
|
||||
elseif ANT.direction == "d" then
|
||||
ANT.y = ANT.y + UNITS
|
||||
else
|
||||
ANT.x = ANT.x - UNITS
|
||||
end
|
||||
for _ = 1, STEPS_PER_FRAME do
|
||||
local c = nextColor()
|
||||
ANT.direction = rotate(ANT.direction, c.clockwise)
|
||||
CANVAS:renderTo(function()
|
||||
love.graphics.setBlendMode("alpha")
|
||||
love.graphics.setColor(c.rgba)
|
||||
love.graphics.rectangle("fill", ANT.x, ANT.y, UNITS, UNITS)
|
||||
end)
|
||||
if ANT.direction == "u" then
|
||||
ANT.y = ANT.y - UNITS
|
||||
elseif ANT.direction == "r" then
|
||||
ANT.x = ANT.x + UNITS
|
||||
elseif ANT.direction == "d" then
|
||||
ANT.y = ANT.y + UNITS
|
||||
else
|
||||
ANT.x = ANT.x - UNITS
|
||||
end
|
||||
|
||||
if ANT.x >= WIDTH then
|
||||
ANT.x = 0
|
||||
elseif ANT.x < 0 then
|
||||
ANT.x = (WIDTH - 1) - ((WIDTH - 1) % UNITS)
|
||||
end
|
||||
if ANT.y >= HEIGHT then
|
||||
ANT.y = 0
|
||||
elseif ANT.y < 0 then
|
||||
ANT.y = (HEIGHT - 1) - ((HEIGHT - 1) % UNITS)
|
||||
if ANT.x >= WIDTH then
|
||||
ANT.x = 0
|
||||
elseif ANT.x < 0 then
|
||||
ANT.x = (WIDTH - 1) - ((WIDTH - 1) % UNITS)
|
||||
end
|
||||
if ANT.y >= HEIGHT then
|
||||
ANT.y = 0
|
||||
elseif ANT.y < 0 then
|
||||
ANT.y = (HEIGHT - 1) - ((HEIGHT - 1) % UNITS)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue