1. The line segment from vertex 1 to 2 isn't connecting.
2. The fill is skipping vertex 2, 3 and 4.
Here is the code:
Code: Select all
function love.load()
love.window.setMode(800, 600)
vertices = {
50, 136,
114, 181,
321, 107,
422, 87,
579, 57,
609, 54,
639, 52,
653, 52,
686, 61,
750, 136,
750, 380,
50, 380,
50, 136,
}
end
function love.draw()
math.randomseed(0)
love.graphics.setColor(255, 0, 0)
love.graphics.polygon('fill', vertices)
love.graphics.setColor(0, 255, 0)
love.graphics.polygon('line', vertices)
love.graphics.setPointSize(5)
for i = 1, #vertices, 2 do
love.graphics.setColor(0, 0, 255)
love.graphics.point(vertices[i], vertices[i + 1])
love.graphics.print(i/2 + 0.5, vertices[i] + math.random(-1, 1), vertices[i + 1] + math.random(-10, 10))
end
love.graphics.setColor(255, 255, 255)
love.graphics.print(string.format('convex: %s', love.math.isConvex(vertices)))
end
Edit: Resolved in IRC thanks to bartbes. The issue is with last vertex, which is a repeat of the first one. I thought you had to close the polygon that way, but turns out you don't. If I remove the repeat vertex, the line segments get drawn correctly, but the fill is still wrong because the polygon is not convex, as reflected correctly by love.math.isConvex().