Sync On
Sync Rate 60
Randomize Timer()
Autocam Off
 
Type Coordinates
   x as Float
   y as Float
   z as Float
Endtype
Global Object as Coordinates
Global Target as Coordinates
Global Total as Coordinates
Global Count as Float
 
Dim m(1000) as Float
R# = 3        :` resting length
K# = .5  :` spring coefficient
v# = 0.0       :` velocity
f# = 0.9       :` friction
 
Dim dots(1000) as Coordinates
Dim vels(1000) as Coordinates
 
For i = 1 to 1000
   Make Object Sphere i,.5,8,8
   Position Object i,0,0,0
   Turn Object Right i,rnd(360)
   Pitch Object Down i,rnd(360)
   Roll Object Left i,rnd(360)
   Move Object i,rnd(R#)+.1
   m(i)=rnd(500.0)/5.0+1.0
   Return_Object(i)
   dots(i).x=Object.x:dots(i).y=Object.y:dots(i).z=Object.z
Next i
Make Object Sphere 1001,.5,8,8
Position Object 1001,0,0,50
 
 
Count=249
Do
   Fix Object Pivot 1001
   Move Object Right 1001,MouseMoveX()/4
   Move Object Down 1001,MouseMoveY()/4
   Return_Object(1001)
   cx#=Object.x:cy#=Object.y:cz#=Object.z
   Total.x=0:Total.y=0:Total.z=0
   For i =1 to 1000
      Return_Target(i)
      Total.x=Target.x+Total.x
      Total.y=Target.y+Total.y
      Total.z=Target.z+Total.z
   Next i
   cx#=(cx#*500.0+Total.x)/1500.0:cy#=(cy#*500.0+Total.y)/1500.0:cz#=(cz#*500.0+Total.z)/1500.0
   For i = 1 to 1000
      Return_Target(i)
      dx#=Target.x-(cx#+dots(i).x)
      vels(i).x=Spring(vels(i).x,K#,dx#,m(i),f#)
      dy#=Target.y-(cy#+dots(i).y)
      vels(i).y=Spring(vels(i).y,K#,dy#,m(i),f#)
      dz#=Target.z-(cz#+dots(i).z)
      vels(i).z=Spring(vels(i).z,K#,dz#,m(i),f#)
      Position Object i,Target.x+vels(i).x,Target.y+vels(i).y,Target.z+vels(i).z
      Return_Target(i)
   Next i
   Set Cursor 0,0
   Print Screen FPS()
   Sync
Loop
 
 
 
 
Function Spring(vel#,spring#,dist#,resist#,frict#)
vel#=(vel# + (-spring# * dist#)/resist#)*frict#
EndFunction vel#
 
 
Function Return_Object(ObjectID)
Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID):Object.z=Object Position Z(ObjectID)
EndFunction
 
Function Return_Target(TargetID)
Target.x=Object Position X(TargetID):Target.y=Object Position Y(TargetID):Target.z=Object Position Z(TargetID)
EndFunction