Listing 2 'APOLLO11.BAS DECLARE SUB Init () : DECLARE SUB Tidyup () 'SETTTING UP CORE PROGRAM ON VGA SCREEN SCREEN 12: pi = 4 * ATN(1): pi2 = pi * 2 'pi=4*45 degrees emmr = 81.3: emd = 384235'earth/moon mass ratio & distance ce = emd / (1 + emmr): cm = emd - ce 'e/centre/m distances Erad = 6378: gce = .0098 * Erad * Erad 'earth & moon radii Mrad = 1738: gcm = gce / emmr '...and gravity consts angm0 = pi2 * 294.5 / 360 'angle of moon at launch dangm = pi2 / (654.2 * 3600)'moon angular vel. radians/sec de1 = Erad + 180: eg = gce / (de1 * de1) 'orbit gravity & cv = SQR(eg * de1) 'circular velocity & period (88.1 min) circum = pi2 * de1: period = circum / (cv * 60) an = 360! * 2400 / circum 'angle launch to orbit (21 deg) apogee = 549200 'Notional apogee to intercept moon Sector = 1: t = 5100: tm = 85 'start at 5100 sec = 85 min ts = 9945:ti = 1 'start TLI burn at ts secs, time interval angm =angm0+t*dangm: s=SIN(angm): c=COS(angm) 'moon angle xe =-ce *c: ye =-ce *s: xm =cm *c: ym=cm *s 'e/m positions 'IF colour = 1 THEN 'commented out this month CALL Init: CIRCLE (xe, ye), Erad, 2 'earth, lit by sun LINE(xe -Erad, ye)-(xe +Erad,ye),2:PAINT(xe, ye -1000), 2 FOR angle = 221 TO 243 STEP .05 'mark launch sector red LINE (xe, ye)-STEP(Erad * COS(angle / 57.3), .... Erad * SIN(angle / 57.3)), 4: NEXT 'move to line above LINE(-15000, 0)-(6000, 0),15:LINE(0, -6000)-(0, 11000),15 LINE(-15000,ye)-(6000,ye),15:LINE(xe,-6000)-(xe,11000),15 LINE(0,0)-(8000 *COS(294 / 57.3), 8000 * SIN(294 / 57.3)) 'END IF 'commented out this month x = xe - de1: y = ye: u = 0: v = -cv 'initial pos. & vel. m = 61199 + 83811 'mass of ship + remnant Stage 3 fuel tl = 92627: thr = tl * .0098 'thrust, kgf and kga SI3 = 420: ff = tl / SI3 'Specific Impulse, fuel flow tf3 = 83811 'remnant Stage 3 fuel DO: t = t + ti 'THIS IS THE MAIN PROGRAM LOOP 'NOW FOR CODE USED IN ALL SECTORS angm = angm0 + dangm * t: c = COS(angm): s = SIN(angm) xm = cm * c: ym = cm * s: xe = -ce * c: ye = -ce * s dmx = xm - x: dmy = ym - y 'Apollo/moon x&y separations dm2 = dmx * dmx + dmy * dmy: dm = SQR(dm2) ' " distance gm = gcm / dm2 'acceleration towards moon mx = gm * dmx / dm: my = gm * dmy / dm 'accel. components dex = xe - x: dey = ye - y 'Apollo/earth x&y separations de2 = dex * dex + dey * dey: de = SQR(de2) ' " distance eg = gce / de2 'acceleration towards earth ex = eg * dex / de: ey = eg * dey / de 'accel. components gx = ex+mx+atx: gy = ey+my+aty 'total Apollo acc. comps u = u + ti * gx: v = v + ti * gy 'increment velocity x = x + ti * u: y = y + ti * v 'increment position w2 = u * u + v * v: w = SQR(w2) 'magnitude of velocity E = w2 / 2 - gce / de - gcm / dm 'total energy IF t MOD 60 = 0 THEN 'each minute adjust min and hr tm = t / 60: hr = INT(tm / 60): min = tm MOD 60 END IF tp = t - 29000 'position along x axis to plot... PSET (tp, 7500 + E * 500), 4 '...specific total energy... PSET (tp, w * 4000 - 38000), 2 '...and velocity PSET (x, y), 15 'also plot position SELECT CASE Sector'FOLLOWING CODE SPECIFIC TO EACH SECTOR CASE 1: 'LAST EARTH ORBIT IF t = ts THEN 'start burn to head for moon rv2 = gce * 2 * apogee /(de*(de+apogee)) 'required vel Erq = rv2 / 2 - gce / de - gcm / dm: Sector = 2 END IF 'Sets required energy to attain in Sector 2 CASE 2: 'TRANS LUNAR INJECTION BURN IF E < Erq THEN 'not yet reached required energy acc =thr /(m -ff/ 2): m = m -ff 'acceleleration & mass ang =ATN(-(y - ye) / (x - xe)) 'thrust kept horizontal atx = -acc *SIN(ang): aty = -acc *COS(ang) 'components LINE (x, y)-(xe, ye), 4 'mark firing Sector in red ELSE 'has exceeded required energy wr =SQR(2 * (Erq + gce /de + gcm /dm)) 'required vel. u =u * wr /w: v =v * wr /w 'reduce u & v to exact Erq Sector = 3: atx = 0: aty = 0 'cut thrust and coast 'IF colour = 1 THEN 'commented out this month LOCATE 21, 26: PRINT "Firing Stage 3 for TLI." LOCATE 22, 26 PRINT "Escape energy OK. Velocity ="; wr; "km/s." LOCATE 23, 26: PRINT "Stage 3 fuel remaining ="; PRINT CINT(m - 61199); "kgs." 'END IF 'commented out this month END IF CASE 3: 'COASTING AFTER BURN IF t MOD 60 = 0 THEN 'each minute, print on screen LOCATE 24:PRINT hr;"h"; min;"m, "; w; 'note last ";" PRINT "km / sec "; de; " km radius": IF tm = 190 THEN 'end Sector 3 at 190 min CALL Tidyup 'rearrangement of Apollo configuration Sector = 4 'CASE ELSE will terminate since no CASE 4 END IF END IF CASE ELSE: finish = 1 'will only run any Sector included END SELECT LOOP UNTIL finish = 1 DO: LOOP WHILE INKEY$ = "" SUB Init WINDOW (-30000, -16500)-(10000, 13500) COLOR 2: FOR n =8 TO 12: LOCATE 52-n * 4, 9: PRINT n: NEXT LOCATE 8, 15: PRINT "Velocity": COLOR 4 FOR n = 0 TO 3: LOCATE 6 + n * 5, 3: PRINT -n * 10: NEXT LOCATE 6, 8: PRINT "Specific Energy" FOR yc = -7500 TO 7500 STEP 5000 'Specific Energy scale LINE (-29500, yc)-(-28900, yc), 4: NEXT FOR yc = -10000 TO 10000 STEP 500 'ditto LINE (-29500, yc)-(-29300, yc), 4: NEXT FOR yc = -10000 TO 10000 STEP 4000 'Velocity scale LINE (-26000, yc)-(-25500, yc), 2: NEXT FOR yc = -9200 TO 9200 STEP 800 'ditto LINE (-26000, yc)-(-25850, yc), 2: NEXT: COLOR 15 LOCATE 15, 33: PRINT "-x": LOCATE 15, 70: PRINT "+x" LOCATE 15, 46: PRINT "L": LOCATE 6, 42: PRINT "TLI" LOCATE 3,61:PRINT "+y": LOCATE 19,61: PRINT "-y To Moon" LOCATE 1, 6: PRINT "Apollo 11 spent 2 hrs 30 mins "; PRINT "establishing exact orbit before": PRINT " TLI, when Stage 3 burnt "; PRINT "to attain energy to reach moon.": LOCATE 28, 22: PRINT "Stage 3 & IU LEM" LOCATE 28, 53: PRINT "SM CM" LINE (-25000, -13000)-(-21000, -13600), 7 'Stage 3 engine LINE (-25000, -15000)-(-21000, -14400), 7 'ditto LINE (-21000, -16200)-(-12780, -11800), 7, B 'Stage 3 & IU LINE (-13380, -16200)-(-13380, -11800), 7 'ditto LINE (-12780, -16200)-(-7180,-15300), 7 'LEM tapered cover LINE (-12780, -11800)-(-7180, -12700), 7 'Lunar Module LINE (-7180, -15300)-(-2100, -12700), 7, B 'Service Module LINE (-5580, -15300)-(-5580, -12700), 7 'SM cross LINE (-2100, -15300)-(300, -14300), 7 'Command Module LINE (-2100, -12700)-(300, -13700), 7 'ditto LINE (300, -14300)-(300, -13700), 7 'nose END SUB SUB Tidyup LOCATE 25: PRINT "The conical fairing is discarded"; PRINT ", exposing the LEM and freeing the CM/SM.": DO: LOOP WHILE INKEY$ = "" LINE (-12780, -16200)-(-7180, -15300), 0 'LEM cover LINE (-12780, -11800)-(-7180, -12700), 0 'ditto LINE (-12780, -12300)-(-9800, -15700), 7, B 'LEM LINE (-9800, -12700)-(-7800, -15300), 7, B 'LEM LINE (-11800, -12300)-(-11800, -15700), 7 'LEM LOCATE 25: PRINT "The Command Module/ Service Module "; PRINT "are rotated"; SPC(28); : DO: LOOP WHILE INKEY$ = "" LINE (-7200, -15300)-(300, -12700), 0, BF 'SM & CM LOCATE 28, 50: PRINT "CM SM" LINE (-4000, -15300)-(1100, -12700), 7, B 'SM LINE (-500, -15300)-(-500, -12700), 7 'SM LINE (-4000, -15300)-(-6400, -14400), 7 'CM LINE (-4000, -12700)-(-6400, -13600), 7 'CM LINE (-6400, -13600)-(-6400, -14400), 7 'CM LOCATE 25: PRINT "And connected again to the LEM "; PRINT "docking hatch. ": DO: LOOP WHILE INKEY$ = "" LINE (-6400, -15300)-(1100, -12700), 0, BF 'SM LOCATE 28, 47: PRINT "CM SM" LINE (-5400, -15300)-(-300, -12700), 7, B 'SM LINE (-1900, -15300)-(-1900, -12700), 7 'SM LINE (-5400, -15300)-(-7800, -14400), 7 'CM LINE (-5400, -12700)-(-7800, -13600), 7 'CM LINE (-7800, -13600)-(-7800, -14400), 7 'CM LOCATE 25: PRINT "The spent Stage 3 and Instrument Unit"; PRINT " are now jettisonned": DO: LOOP WHILE INKEY$ = "" LINE (-25000, -11800)-(-11900, -16200), 0, BF: LOCATE 25 PRINT "Interstage discarded to reveal SM motor."; PRINT SPC(30); : DO: LOOP WHILE INKEY$ = "" LINE (-1800, -15300)-(-300, -12700), 0, B 'interstage LINE (-1900, -13700)-(-300, -13300), 7 'motor LINE (-1900, -14300)-(-300, -14900), 7 'ditto END SUB