Skip to content

Instantly share code, notes, and snippets.

@flamendless
Last active September 28, 2018 04:39
Show Gist options
  • Save flamendless/e0d3a09906bd990251988fccdd7b7ba0 to your computer and use it in GitHub Desktop.
Save flamendless/e0d3a09906bd990251988fccdd7b7ba0 to your computer and use it in GitHub Desktop.
Interpolate a circle to another circle (number of points/2)
local processPoints = function(shape1, shape2)
local d = #shape1/#shape2 * 2
local all = {}
for i = 1, #shape1, 2 do
all[i] = false
if i % d == 1 then
all[i] = true
end
end
return all
end
local startTransform = function(t, from, to)
local n = 1
local m = 1
for k,v in pairs(t) do
local x = k
local y = k + 1
if v then
flux.to(from, 4, { [x] = to[n], [y] = to[n+1] })
n = n + 2
else
local x1 = m
local y1 = m+1
local x2 = m+2
local y2 = m+3
if x2 > #to then x2 = 1 end
if y2 > #to then y2 = 2 end
local mx = (to[x1] + to[x2])/2
local my = (to[y1] + to[y2])/2
flux.to(from, 4, { [x] = mx, [y] = my })
m = m + 2
end
end
end
function doTest(n)
local w = love.graphics.getWidth()
local h = love.graphics.getHeight()
circle = draft:circle(w/2, h/2, 512, n, "line")
circle2 = draft:circle(w/2, h/2, 256, n/2, "line")
rectangle = draft:rectangle(w/2, h/2, 128, 128, "line")
points = processPoints(circle, circle2)
startTransform(points, circle, circle2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment