Sync On
Sync Rate 60
Autocam Off
Spring_Primitive(1,6,20,4)
 
Position Object 1,0,-15,15
Do
   Move Camera Upkey()-Downkey()
   Turn Camera Left Leftkey()-RightKey()
   Sync
Loop
 
 
Function Spring_Primitive(ObjectID,coils#,height#,radius#)
   Make Object Cylinder ObjectID,1
   Pitch Object Down ObjectID,90
   Fix Object Pivot ObjectID
   Make Mesh From Object ObjectID,ObjectID
   Pitch Object Up ObjectID,90
   Fix Object Pivot ObjectID
   OffSet Limb ObjectID,0,sin(360)*radius#,0,cos(360)*radius#
   For i# = 1.0 to 360.0
      Add Limb ObjectID,i#,ObjectID
      OffSet Limb ObjectID,i#,sin(i#*coils#)*radius#,i#*(height#/360.0),cos(i#*coils#)*radius#
      plimbx#=Limb Position X(ObjectID,i#-1)
      plimby#=Limb Position Y(ObjectID,i#-1)
      plimbz#=Limb Position Z(ObjectID,i#-1)
      nlimbx#=Limb Position X(ObjectID,i#)
      nlimby#=Limb Position Y(ObjectID,i#)
      nlimbz#=Limb Position Z(ObjectID,i#)
      dx#=nlimbx#-plimbx#:dy#=nlimby#-plimby#:dz#=nlimbz#-plimbz#
      d#=sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
      Rotate Limb ObjectID,i#,-Atanfull(dy#,d#),Atanfull(dx#,dz#),0
   Next i#
   plimbx#=Limb Position X(ObjectID,1)
   plimby#=Limb Position Y(ObjectID,1)
   plimbz#=Limb Position Z(ObjectID,1)
   nlimbx#=Limb Position X(ObjectID,0)
   nlimby#=Limb Position Y(ObjectID,0)
   nlimbz#=Limb Position Z(ObjectID,0)
   d#=sqrt((dx#*dx#)+(dy#*dy#)+(dz#*dz#))
   dx#=nlimbx#-plimbx#:dy#=nlimby#-plimby#:dz#=nlimbz#-plimbz#
   Rotate Limb ObjectID,0,90-Atanfull(dy#,d#),Atanfull(dx#,dz#),0
   Delete Mesh ObjectID
   Make Mesh From Object ObjectID,ObjectID
   Delete Object ObjectID
   Make Object ObjectID,ObjectID,0
EndFunction