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)
-- Do your drawing here
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 = poses[i]:rotate(math.rad(angle))
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