Created
January 18, 2020 21:03
-
-
Save martin-braun/18ee8f6dfbf4051dcde25b3e63b4f0e2 to your computer and use it in GitHub Desktop.
Shape transformer experiment using LÖVE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local x, y = 400, 300 | |
local lineLength = 150 | |
local rotationChange = -0.003 | |
function rotateAround(x1, y1, x2, y2, r) | |
local c, s = math.cos(r), math.sin(r) | |
return c * (x1 - x2) - s * (y1 - y2) + x2, s * (x1 - x2) + c * (y1 - y2) + y2 -- rotate x1,y1 around x2,y2 by r | |
end | |
local c, curR, addR | |
function love.load() | |
c = love.graphics.newCanvas(800, 600) | |
curR = 0 | |
addR = math.pi | |
y = y - lineLength / 2 | |
end | |
function love.draw() | |
local curX, curY = x, y | |
addR = addR + rotationChange | |
curR = curR + addR | |
x, y = rotateAround(curX, curY - lineLength, curX, curY, curR) | |
love.graphics.setCanvas(c) | |
love.graphics.setColor(0, 0, 0, 0.015) | |
love.graphics.rectangle("fill", 0, 0, 800, 600) | |
love.graphics.setColor(0, 1, 0, 1) | |
love.graphics.line(curX, curY, x, y) | |
love.graphics.setCanvas(nil) | |
love.graphics.draw(c) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment