' Initial conditions
dt = .03
delayfactor = 500000
m = 1 ' Mass
g = 1 ' Gravity constant
l = 1 ' Pendulum length
q10 = 0 ' Initial angle (vertical)
p10 = 1.5 ' Initial momentum (a kick to the right)
scalebig = 10: scalesmall = 5 * dt
' Main loop.
iterations = 0
q1 = q10
p1 = p10
q2 = q20
p2 = p20
q1temp = q1
p1temp = p1
q2temp = q2
p2temp = p2
' Plane pendulum calculations
''' What's wrong with these?
q1 = q1temp + (p1temp / m) * dt
p1
= p1temp
- (g
/ l
) * SIN(q1temp
) * dt
''' These aren't quite right...
x = (iterations * scalesmall - 180)
CALL cpset
(x
, (q1
* scalebig
+ 160), Yellow
) ' q1 plot CALL cpset
(x
, (p1
* scalebig
+ 60), Yellow
) ' p1 plot CALL cpset
(x
, (q2
* scalebig
- 60), Red
) ' q2 plot CALL cpset
(x
, (p2
* scalebig
- 160), Red
) ' p2 plot iterations = 0
' Phase portrait
CALL cpset
((q1temp
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (p1temp
* (2 * scalebig
) + 100), Yellow
) CALL cpset
((q1
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (p1
* (2 * scalebig
) + 100), White
) CALL cpset
((q2temp
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (p2temp
* (2 * scalebig
) + 100), Red
) CALL cpset
((q2
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (p2
* (2 * scalebig
) + 100), White
)
' Position portrait
CALL cpset
((q1temp
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (q2temp
* (2 * scalebig
) - 100), Blue
) CALL cpset
((q1
* (2 * scalebig
) + (190 + (320 - _WIDTH / 2))), (q2
* (2 * scalebig
) - 100), White
)
' Pendulum
CALL cline
(200, 0, 400, 0, White
) CALL cline
(300, 0, 300 + 100 * SIN(q1temp
), -100 * COS(q1temp
), Black
) CALL cline
(300, 0, 300 + 100 * SIN(q1
), -100 * COS(q1
), Blue
)
iterations = iterations + 1
drawaxes:
' Axis for q1 plot
' Axis for p1 plot
' Axis for q2 plot
' Axis for p2 plot
' Axes for q & p plots
CALL cline
((190 + (320 - _WIDTH / 2)), 80 + 100, (190 + (320 - _WIDTH / 2)), -80 + 100, Gray
) CALL cline
((190 + (320 - _WIDTH / 2)) - 100, 100, (190 + (320 - _WIDTH / 2)) + 100, 100, Gray
) CALL cline
((190 + (320 - _WIDTH / 2)), -80 - 100, (190 + (320 - _WIDTH / 2)), 80 - 100, Gray
) CALL cline
((190 + (320 - _WIDTH / 2)) - 100, -100, (190 + (320 - _WIDTH / 2)) + 100, -100, Gray
)