# Softbodies

The function makejelli(x,y,size,angle,squishiness) returns a table holding five circle bodies- the first four are corners and the fifth is a center part that is slightly more massive than the others.

Note that the “walls” of the jelli box are not solid, because I lost interst in this coding dongle before I finished them.

``````-- Use this function to perform your initial setup
function setup()
iparameter("xforce",-5,5,0)
physics.body(EDGE,vec2(0,0),vec2(WIDTH,0))
print("Hello World!")
thingy = makejelli(333,333,99,math.random(0,90),2)
end

-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)

-- This sets the line thickness
strokeWidth(5)

drawjelli(thingy)
end

function makejelli(xx,yy,dist,angle,squish)
local squishy = 4/squish
local poses = {
vec2(-dist,-dist),
vec2(dist,-dist),
vec2(dist,dist),
vec2(-dist,dist),
vec2(0,0)
}
local derps = {}
for i = 1,5 do
local merr = 0
if i == 5 then
merr = physics.body(CIRCLE,4)  else
merr = physics.body(CIRCLE,3) end
merr.position = merr.position + vec2(xx,yy)
merr.fixedRotation = true
merr.linearVelocity= vec2(math.random(-1,1),math.random(-1,1))
merr.friction = 1.1
derps[i] = merr
end

for j = 1,4 do
local aa = derps[5]
local bb = derps[j]
local mup =    physics.joint(DISTANCE,aa,bb,aa.position,bb.position)
mup.frequency = 222/dist*squishy

for k = 1,4 do

if j~= k then
local aa = derps[j]
local bb = derps[k]
local mup =    physics.joint(DISTANCE,aa,bb,aa.position,bb.position)
if math.abs(j-k) == 2 then mup.frequency = 88/dist*squishy else
mup.frequency = 66/dist*squishy end
end

end
end

return derps
end

function drawjelli(derps)

for j = 1,5 do
for k = 1,5 do

if j~= k then
local aa = derps[j]
local bb = derps[k]
line(aa.x,aa.y,bb.x,bb.y)
end

end
end

end

``````

Wow cool

But there’s sum bug’s

Declaring that there are bugs is completely unhelpful. What bugs are there, when do they show up, what do they do?

A bug run it in 30-60 seconds it will bug

Fixed.

Great!

Very neat, @KMEB. Such a tiny amount of code, too.

The joints break if I draw a mesh onto it, however, and I cannot figure out why