Hey, @dave1707, I thought your revolute man needed some boundaries. It’s fun watching him dance around the screen.
-- Revolute-Man V2
-- Inspiration by: dave1707
-- Mods by Scotty
displayMode(STANDARD)
function setup()
print("Use touch to set Revolute-Man in motion.")
parameter.integer("use_accelerometer", 0, 1,0)
X = WIDTH/2
Y = HEIGHT/2
neck = 20
arm = 70
body = 180
leg = 100
physics.continuous=true
physics.gravity(0,-10)
p1=physics.body(CIRCLE,10)
p1.x=X
p1.y=Y
p2=physics.body(CIRCLE,5)
p2.x=X
p2.y=Y-neck
p3=physics.body(CIRCLE,5)
p3.x=X-arm
p3.y=Y-neck
p4=physics.body(CIRCLE,5)
p4.x=X+arm
p4.y=Y-neck
p5=physics.body(CIRCLE,5)
p5.x=X
p5.y=Y-neck-body
p6=physics.body(CIRCLE,5)
p6.x=X-leg
p6.y=Y-neck-body
p7=physics.body(CIRCLE,5)
p7.x=X+leg
p7.y=Y-neck-body
jnt1=physics.joint(REVOLUTE,p1,p2,p1.position)
jnt2=physics.joint(REVOLUTE,p2,p3,p2.position)
jnt3=physics.joint(REVOLUTE,p2,p4,p2.position)
jnt4=physics.joint(REVOLUTE,p2,p5,p2.position)
jnt5=physics.joint(REVOLUTE,p5,p6,p5.position)
jnt6=physics.joint(REVOLUTE,p5,p7,p5.position)
fill(255)
stroke(255)
strokeWidth(2)
lineWidth = 4
-- Draw a boarder, one pixel in, using the same values for vec2() and lines.
-- Going CCW around the screen we have:
LLX = lineWidth/2
LLY = lineWidth/2
LRX = WIDTH-lineWidth/2
LRY = lineWidth/2
URX = WIDTH-lineWidth/2
URY = HEIGHT-lineWidth/2
ULX = lineWidth/2
ULY = HEIGHT-lineWidth/2
CreateWalls() -- this will create all the required walls or bountries. CALLED FROM setup()
defaultGravity = physics.gravity()
end
function draw()
if use_accelerometer == 1 then
physics.gravity(Gravity)
else
physics.gravity(defaultGravity)
end
-- Draw Revolute-Man
background(0)
fill(255, 255, 255, 255)
stroke(255, 255, 255, 255)
strokeWidth(2)
ellipse(p1.x,p1.y,20)
--face
pushStyle()
fill(0, 0, 0, 255)
stroke(0, 0, 0, 255)
ellipse(p1.x+4,p1.y+4,4)
ellipse(p1.x-4,p1.y+4,4)
ellipse(p1.x,p1.y-4,8)
popStyle()
ellipse(p2.x,p2.y,10)
ellipse(p3.x,p3.y,10)
ellipse(p4.x,p4.y,10)
ellipse(p5.x,p5.y,10)
ellipse(p6.x,p6.y,10)
ellipse(p7.x,p7.y,10)
line(p1.x,p1.y-8,p2.x,p2.y)
line(p2.x,p2.y,p3.x,p3.y)
line(p2.x,p2.y,p4.x,p4.y)
line(p2.x,p2.y,p5.x,p5.y)
line(p5.x,p5.y,p6.x,p6.y)
line(p5.x,p5.y,p7.x,p7.y)
-- Draw four sides (different colors so you know what's going on)
strokeWidth(lineWidth)
stroke(255, 0, 0, 255)
line(LLX,LLY,LRX,LRY) -- sending same two x,y pairs as sent to CreateWall()
stroke(255, 0, 204, 255)
line(LRX,LRY,URX,URY)
stroke(134, 0, 255, 255)
line(URX,URY,ULX,ULY)
stroke(0, 255, 55, 255)
line(ULX,ULY,LLX,LLY)
end
function touched(t)
if t.state==MOVING then
p5.linearVelocity=vec2(t.deltaX*20,t.deltaY*20)
end
end
-- I can't take full credit for the following two functions.
-- This function() calls CreateWall() which in turn creates a physical edge-type body.
-- Sending the same values as you would use to draw lines on top of the edges.
function CreateWalls()
local r=2.5
leftWall = CreateWall(LLX,LLY,ULX,ULY,r) -- sending two x,y pairs and restitution
rightWall = CreateWall(LRX,LRY,URX,URY,r)
bottomWall = CreateWall(LLX,LLY,LRX,LRY,r)
topWall = CreateWall(ULX,ULY,URX,URY,r)
end
-- This function() does the actual creation of a physical edge-type body.
-- Line locs are converted into vecs().
function CreateWall(x,y,x1,y1,r)
local w = physics.body(EDGE,vec2(x,y),vec2(x1,y1)) -- using two vec2() pairs
w.restitution=r
return w
end