-- Draw polygon as triangle function love.load() polys = { {40,80,100,20,200,80,180,220,100,260,20,200}, {340,280,300,200,440,180,380,80,460,60,500,160,600,160,620,260,520,300,500,260} } end function love.update(dt) end function love.draw() love.graphics.clear(0, 0, 0, 1) for i, v in ipairs(polys) do local convex = love.math.isConvex(v) if convex then love.graphics.setColor(0, 0.75, 0, 1) love.graphics.polygon("fill", v) else local col = {{0,0,1}, {0,0.25,1}, {0,0.5,1}, {0,0.75,1}} local triangles = love.math.triangulate(v) for i = 1, #triangles do love.graphics.setColor(unpack(col[(i % #col) +1])) love.graphics.polygon("fill", triangles[i]) end end love.graphics.setColor(1, 0, 0, 1) love.graphics.polygon("line", v) love.graphics.setColor(1, 1, 1, 1) local s = convex and "true" or "false" love.graphics.print("Convex : " .. s, 4, i * 20 + 20) end love.graphics.setColor(1, 1, 1, 1) love.graphics.print("ESC to exit.", 4, 4) end function love.keypressed(key, scancode, isrepeat) if key == "escape" then love.event.quit() end end