Helps me keep my pictures a little neater.
ULMLUS5MKUI6OROPBSXEDAD6VYL5UH2SZSEAVCTQBNKGNKCCN6WQC
base_for_zoom = function(base)
local n = base
while scale(n) < base/2 do
if scale(n*base) < base/2 then
n = n*base
else -- scale linearly
local n2 = n
while scale(n2) < base/2 do
n2 = n2+n
end
return n2
end
end
return n
end
floor_to = function(n, base)
return math.floor(n/base)*base
end
draw_grid = function()
love.graphics.setColor(0.8, 0.8, 0.8)
local xlo, xhi = sx(0), sx(Viewport.w)
local ylo, yhi = sy(0), sy(Viewport.h)
local base = base_for_zoom(100)
xlo, xhi = floor_to(xlo, base), floor_to(xhi, base)+base
ylo, yhi = floor_to(ylo, base), floor_to(yhi, base)+base
for x = xlo, xhi, base do
love.graphics.line(vx(x), 0, vx(x), Viewport.h)
end
for y = ylo, yhi, base do
love.graphics.line(0, vy(y), Viewport.w, vy(y))
end
end
on.resize = function(w, h)
Viewport.w, Viewport.h = w, h
end