-- Textured Polygon Demo -- request love2d 11.3 -- -- Original xXxMoNkEyMaNxXx -- fork drunken_munki -- fork mieki256 function love.load() tp = require 'Perspective' love.graphics.setDefaultFilter("linear", "linear", 2) img = love.graphics.newImage('textures/uvcheckermap01-512.png') -- img = love.graphics.newImage('textures/ff nub.png') -- img = love.graphics.newImage('textures/lenaC.jpg') vert = {{100, 100}, {400, 100}, {400, 400}, {100, 400}} -- Try uncommenting one of these! 600 is the image size.-- -- tp:setRepeat({0.25,0.25},{0.75,0.75}) -- tp:setRepeat({253/600,50/600},{80/600,80/600}) -- Dragging Vertices & Colour (for demonstration purposes)-- love.graphics.setBackgroundColor(0.2, 0.2, 1, 1) dragging = nil offset = {0, 0} rgba = {1, 1, 1, 1} end function love.update(dt) -- drag vertex local x, y = love.mouse.getPosition() local b1d = love.mouse.isDown(1) if dragging then vert[dragging][1] = x + offset[1] vert[dragging][2] = y + offset[2] if not b1d then dragging = nil end elseif b1d then local vc local best = math.huge for i, v in next, vert do local dis = math.sqrt((v[1] - x) ^ 2 + (v[2] - y) ^ 2) if dis < best then vc, best = i, dis end end dragging = vc offset[1] = vert[vc][1] - x offset[2] = vert[vc][2] - y end -- change color local t = love.timer.getTime() % math.pi rgba[1] = math.sin(t) ^ 2 rgba[2] = math.sin(t + math.pi / 3) ^ 2 rgba[3] = math.sin(t + 2 * math.pi / 3) ^ 2 rgba[4] = math.cos(love.timer.getTime() * 2 ^ 0.5) ^ 2 end function love.draw() -- Yep, that's it! love.graphics.setColor(rgba[1], rgba[2], rgba[3], rgba[4]) tp:quad(img, vert[1], vert[2], vert[3], vert[4]) love.graphics.setColor(1, 1, 1, 1) love.graphics.print("FPS: " .. love.timer.getFPS(), 8, 8) end function love.keypressed(key, isrepeat) -- ESC to exit if key == "escape" then love.event.quit() end end