SUB EulerRichardson(pos(),vel(),t,GM,dt,kick_flag$,xsave,ysave) DIM accel(2),velmid(2),posmid(2) GET MOUSE x,y,s IF s = 2 then LET xsave = x ! save position where mouse clicked LET ysave = y LET kick_flag$ = "on" END IF IF (kick_flag$ = "on") then LET diffx = abs(pos(1) - xsave) LET diffy = abs(pos(2) - ysave) ! wait until orbit reaches point where mouse clicked IF (diffx < 0.02) and (diffy < 0.02) then LET v2 = vel(1)*vel(1) + vel(2)*vel(2) LET v = sqr(v2) LET impulse = 0.1*v ! magnitude of impulse/mass LET vel(2) = vel(2) + impulse ! vertical kick LET kick_flag$ = "off" END IF END IF ! compute acceleration at beginning of interval CALL acceleration(pos(),accel(),GM) FOR i = 1 to 2 LET velmid(i) = vel(i) + 0.5*accel(i)*dt LET posmid(i) = pos(i) + 0.5*vel(i)*dt NEXT i ! compute acceleration at middle of interval CALL acceleration(posmid(),accel(),GM) ! position and velocity at end of interval FOR i = 1 to 2 LET vel(i) = vel(i) + accel(i)*dt LET pos(i) = pos(i) + velmid(i)*dt NEXT i LET t = t + dt END SUB