I fixed a litle coil spring script:
sync on:sync rate 30
hide mouse
dim spring(11,2)
dim vars#(2,6)
ink 0,0
mass=1:restlength=2:stiffness=3:friction=4:stretch=5:velocity=6
`feel free to change these values, it will change the way the spring behaves
vars#(1,mass)=10
vars#(1,restlength)=50
vars#(1,stiffness)=0.1
vars#(1,friction)=0.1
vars#(2,mass)=5
vars#(2,restlength)=50
vars#(2,stiffness)=0.5
vars#(2,friction)=0.1
do
cls 16777215
set cursor 0,0
print screen fps()
if mouseclick()>0 and mouseclick()<3 then vars#(mouseclick(),stretch)=vars#(mouseclick(),stretch)+mousemovex():vars#(mouseclick(),velocity)=0
if mouseclick()=0
netf#=0-(vars#(1,stiffness)/vars#(1,mass))*vars#(1,stretch)-(vars#(1,friction)/vars#(1,mass))*vars#(1,velocity)
vars#(1,velocity)=vars#(1,velocity)+netf#
vars#(1,stretch)=vars#(1,stretch)+vars#(1,velocity)
netf#=0-(vars#(2,stiffness)/vars#(2,mass))*vars#(2,stretch)-(vars#(2,friction)/vars#(2,mass))*vars#(2,velocity)
vars#(2,velocity)=vars#(2,velocity)+netf#
vars#(2,stretch)=vars#(2,stretch)+vars#(2,velocity)
endif
draw_spring(100.0,100.0,90.0,vars#(1,stretch)+vars#(1,restlength)+0.0)
draw_spring(100.0,120.0,90.0,vars#(2,stretch)+vars#(2,restlength)+0.0)
sync
loop
function draw_spring(posx#,posy#,angle#,dist#)
x=1
y=2
spring(1,x)=posx#
spring(1,y)=posy#
spring(2,x)=newxvalue(posx#,angle#,dist#/16)
spring(2,y)=newzvalue(posy#,angle#,dist#/16)
spring(3,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*1),angle#+90,10)
spring(3,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*1),angle#+90,10)
spring(4,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*2),angle#-90,10)
spring(4,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*2),angle#-90,10)
spring(5,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*3),angle#+90,10)
spring(5,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*3),angle#+90,10)
spring(6,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*4),angle#-90,10)
spring(6,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*4),angle#-90,10)
spring(7,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*5),angle#+90,10)
spring(7,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*5),angle#+90,10)
spring(8,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*6),angle#-90,10)
spring(8,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*6),angle#-90,10)
spring(9,x)=newxvalue(newxvalue(posx#,angle#,dist#/8*7),angle#+90,10)
spring(9,y)=newzvalue(newzvalue(posy#,angle#,dist#/8*7),angle#+90,10)
spring(10,x)=newxvalue(posx#,angle#,dist#/17*16)
spring(10,y)=newzvalue(posy#,angle#,dist#/17*16)
spring(11,x)=newxvalue(posx#,angle#,dist#)
spring(11,y)=newzvalue(posy#,angle#,dist#)
for i = 1 to 10
line spring(i,x),spring(i,y),spring(i+1,x),spring(i+1,y)
next i
endfunction
give comments