I had nothing better to do so I thought I’d try this. It’s 3 wheels connected by a belt. The red wheel is the drive wheel and it’s rotation speed can be controlled by pressing Angular velocity + or - . You can also change the size of the drive wheel using the parameter slide. This doesn’t have any real use other than I wanted to see if I could create a belt that would drive the other wheels.
function setup()
parameter.integer("dr",20,100,50,chg)
chg()
val=0
tab={}
j={}
for z=1,360,5 do
x=math.sin(math.rad(z))*180+390
y=math.cos(math.rad(z))*180+500
table.insert(tab,rope(x,y))
end
for z=1,#tab-1 do
j[z] = physics.joint(ROPE,tab[z].a,tab[z+1].a,
vec2(tab[z].a.x,tab[z].a.y),
vec2(tab[z+1].a.x,tab[z+1].a.y),11)
end
jj=#j+1
j[jj] = physics.joint(ROPE,tab[1].a,tab[jj].a,
vec2(tab[1].a.x,tab[1].a.y),
vec2(tab[jj].a.x,tab[jj].a.y),11)
c1=physics.body(CIRCLE,5)
c1.x=300
c1.y=600
c1.type=STATIC
c2=physics.body(CIRCLE,5)
c2.x=480
c2.y=600
c2.type=STATIC
p1=physics.body(CIRCLE,50)
p1.x=300
p1.y=600
p1.friction=20
p2=physics.body(CIRCLE,60)
p2.x=480
p2.y=600
p2.friction=20
j1=physics.joint(REVOLUTE,c1,p1,c1.position,p1.position)
j2=physics.joint(REVOLUTE,c2,p2,c2.position,p2.position)
end
function chg()
if p3 then
p3:destroy()
c3:destroy()
end
p3=physics.body(CIRCLE,dr)
p3.x=390
p3.y=400
p3.friction=20
c3=physics.body(CIRCLE,5)
c3.x=390
c3.y=400
c3.type=STATIC
j3=physics.joint(REVOLUTE,c3,p3,c3.position,p3.position)
end
function draw()
background(40, 40, 50)
stroke(255)
strokeWidth(2)
noFill()
pushMatrix()
translate(p1.x,p1.y)
rotate(p1.angle)
line(0,0,0,50)
ellipse(0,0,100)
popMatrix()
pushMatrix()
translate(p2.x,p2.y)
rotate(p2.angle)
line(0,0,0,-60)
ellipse(0,0,120)
popMatrix()
pushMatrix()
stroke(255,0,0)
translate(p3.x,p3.y)
rotate(p3.angle)
line(0,0,0,-dr)
ellipse(0,0,dr*2)
popMatrix()
for z=1,#tab do
tab[z]:draw(z)
end
p3.angularVelocity=p3.angularVelocity+val
fill(255)
text(p1.angularVelocity//1,200,600)
text(p2.angularVelocity//1,580,600)
text(p3.angularVelocity//1,390,250)
text("Angular velocity",390,280)
fill(255,0,0)
text("Angular velocity -",390-200,300)
text("Angular velocity +",390+200,300)
text("Drive wheel",390,480)
end
function touched(t)
if t.state==BEGAN then
if t.x>WIDTH/2 then
val=5
else
val=-5
end
end
if t.state==ENDED then
val=0
end
end
rope=class()
function rope:init(x,y,z)
self.a = physics.body(CIRCLE,1)
self.a.x = x
self.a.y = y
self.a.friction=10
end
function rope:draw(z)
strokeWidth(4)
if z>1 then
stroke(255)
line(self.a.x,self.a.y,tab[z-1].a.x,tab[z-1].a.y)
else
stroke(255,0,0)
line(tab[1].a.x,tab[1].a.y,tab[jj].a.x,tab[jj].a.y)
end
end