' Create and draw the strings
GraphicsWindow.PenColor = "Black"
For i = 1 To 3
x1 = i * ballDiam + originX[1]
GraphicsWindow.DrawLine(x1, originY, x1, originY + stringLength)
EndFor
' Set right ball as active
activeBall = 5
inactiveBall = 1
a = activeBall
angle = Math.GetRadians(70)
GraphicsWindow.BrushColor = bgColour
While "True"
start = Clock.ElapsedMilliseconds
update()
elapsedTime = Clock.ElapsedMilliseconds - start
delay = 30 - elapsedTime
If delay > 0 Then
Program.Delay(delay)
EndIf
EndWhile
Sub update
' Update the angular velocity calculations to simulate the pendulum effect
angularAcceleration = -1 * (gravity / stringLength) * Math.Sin(angle)
angularVelocity = angularVelocity + angularAcceleration
angle = angle + angularVelocity
' If ball goes beyond perpendicular then swap to opposite ball
If angle < 0 Then
activeBall = 1
inactiveBall = 5
Else
activeBall = 5
inactiveBall = 1
EndIf
' Play click on ball swap
If a <> activeBall Then
a = activeBall
Sound.PlayClick()
EndIf
' Update balls positions based on which is active and inactive
ballX= Math.Sin(angle) * stringLength + originX[activeBall]
ballY = Math.Cos(angle) * stringLength + originY