Skip to content

Instantly share code, notes, and snippets.

@martin-braun
Created January 18, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin-braun/18ee8f6dfbf4051dcde25b3e63b4f0e2 to your computer and use it in GitHub Desktop.
Save martin-braun/18ee8f6dfbf4051dcde25b3e63b4f0e2 to your computer and use it in GitHub Desktop.
Shape transformer experiment using LÖVE
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