Merge snap.love
This commit is contained in:
commit
7a29c1521a
|
@ -1,4 +1,5 @@
|
|||
on.draw = function()
|
||||
if App.mouse_down(1) then draw_grid() end
|
||||
for _,obj in ipairs(Surface) do
|
||||
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
|
||||
if obj.type == 'rectangle' then
|
||||
|
@ -27,4 +28,4 @@ on.draw = function()
|
|||
love.graphics.circle('fill', vx(Edge.s.sx),vy(Edge.s.sy), 5)
|
||||
love.graphics.circle('fill', vx(Edge.e.sx),vy(Edge.e.sy), 5)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
on.resize = function(w, h)
|
||||
Viewport.w, Viewport.h = w, h
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
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
|
|
@ -0,0 +1,3 @@
|
|||
floor_to = function(n, base)
|
||||
return math.floor(n/base)*base
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
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
|
Loading…
Reference in New Issue