Rope toy

``````function setup()
physics.iterations(11,11)
--  physics.gravity(0,16)
noSmooth()
tspot = physics.body(EDGE,vec2(0,0),vec2(0,0))
tspot.type = STATIC
tspot.position = vec2(555,44)

tspot = physics.body(EDGE,vec2(0,0),vec2(0,0))
tspot.type = STATIC
tspot.position = vec2(555,44)

dude = physics.body(CIRCLE,20)
dude.position = vec2(WIDTH/2,HEIGHT/2)

makeline(tspot,dude)
end

function draw()
tspot.position = vec2(CurrentTouch.x,CurrentTouch.y)/5+ tspot.position*0.8
background(0, 0, 0, 255)
strokeWidth(1.5)
fill(29, 64, 36, 195)
stroke(7, 252, 56, 255)

for i = 2,#ropey do
line(ropey[i].x,ropey[i].y,ropey[i-1].x,ropey[i-1].y)
end
ellipse(dude.x,dude.y,40)

end

function makeline(aa,bb)

ropey = {}
ropeyjoints = {}
local len = math.ceil(aa.position:len(bb.position)/33)
len = 25
ropey[1] = aa
ropey[len] = bb
for i = 2,len-1 do
local me = physics.body(CIRCLE, 2)
me.position = aa.position+(bb.position-aa.position)*(i/len)
me.density = 0
me.fixedRotation = true
ropey[i] = me
end
for i = 1,len-1 do
local cc = ropey[i]
local dd = ropey[i+1]
ropeyjoints[i] = physics.joint(DISTANCE,dd,cc,dd.position,cc.position)
ropeyjoints[i].length = 6
ropeyjoints[i].frequency = 0
ropeyjoints[i].dampingRatio = 0
end
end
``````

Elastiiiiic