Graphics 800,600,0,2
SetBuffer BackBuffer()
Dim String1#(31,1)
Dim String2#(31,1)
Dim Velocity#(31,1)
Const X = 0
Const Y = 1
Const normal_length# = 11
Const damping# = 0.97
For i = 0 To 31
String1(i,X) = 400+i*3
String1(i,Y) = i*11
Next
While Not KeyHit(1)
Cls
For i = 0 To 30
dx1# = GetDiff(i-1,i,X)
dy1# = GetDiff(i-1,i,Y)
mag1# = Length(dx1,dy1)
ext1# = mag1# - normal_length#
dx2# = GetDiff(i,i+1,X)
dy2# = GetDiff(i,i+1,Y)
mag2# = Length(dx2,dy2)
ext2# = mag2# - normal_length#
xvel# = (dx1 / (mag1 * ext1)) + (dx2 / (mag2 * ext2))
yvel# = (dy1 / (mag1 * ext1)) + (dy2 / (mag2 * ext2)) + 10 ;gravity
Velocity#(i,X) = Velocity#(i,X) * damping# + (xvel# * 0.001)
Velocity#(i,Y) = Velocity#(i,Y) * damping# + (yvel# * 0.001)
String2(i,X) = String1(i,X) + Velocity(i,X)
String2(i,Y) = String1(i,Y) + Velocity(i,Y)
Next
String2(0,X) = 400
String2(0,Y) = 0
For i = 1 To 31
String1(i,X) = String2(i,X)
String1(i,Y) = String2(i,Y)
Oval String1(i,X)-5,String1(i,Y)-5,10,10
Line String1(i,X),String1(i,Y),String1(i-1,X),String1(i-1,Y)
Next
If KeyHit(57)
For i = 0 To 31
DebugLog i
DebugLog "X: " + Velocity(i,X)
DebugLog "Y: " + Velocity(i,Y)
DebugLog ""
Next
End If
Flip
Wend
Function GetDiff#(i1,i2,o)
If (i1<0) Or (i2<0) Or (i1>30) Or (i2>30)
Return 0
Else
Return Float(String1(i1,o) - String1(i2,o))
End If
End Function
Function Length#(dx#,dy#)
l# = Sqr(dx^2 + dy^2)
Return l#
End Function
i tried... and failed.
help, anybody? the problem is with the dx2 etc part, ie the next point down...