function love.mousepressed(x, y, button)
if button == 'l' then
if(first == true) then
first = false
fx = x
fy = y
end
table.insert(points,{px = x-fx,py = y-fy})
elseif button == 'r' then
local pol = {}
for i=0,# points,2 do
pol[i] = points[i].px
pol[i+1] = points[i].py
end
-- pol is the table with the array to draw the polygon
points = {}
end
function love.load()
polygon = {}
end
function love.draw()
if #polygon> 4 then
love.graphics.polygon('line',polygon)
end
end
function love.mousepressed(x,y,button)
if button =='l' then
table.insert(polygon,x)
table.insert(polygon,y)
end
end
The #polygon>4 check is just because love.graphics.polygon requires at least 3 vertices. See the wiki, useful stuff there.