Listing 5 'Apolmoon.bas Apollo 11 moon landing and take-off DECLARE SUB Picture (pic) 'draw screen for each event DECLARE SUB DrawLEM1 (x, y) 'draw LEM flying horizontally DECLARE SUB DrawLEM2 (x, y) 'draw LEM landing vertically SCREEN 12: Picture (1) 'VGA, landing or take-off scene MRad = 1738: CMAlt =112: CMR = MRad +CMAlt 'Command Module mgc = 4897: cw =SQR(mgc / CMR ^ 3) 'grav const, CM ang vel angc = -.276: cw5 = cw * 5: 'CM start angle, 5 sec. change ml = 14735: mli = ml 'LEM mass. Record original tl = 4455: thr = tl * .0098 'LEM thrust & acceleration SI = 315: ff = tl / SI: t = 0 'Spec. Impulse & fuel flow h = 15: rm = 1753: an = -.15 'LEM altitude, radius, angle s = SIN(an): c = COS(an): x = rm * s: y = rm * c 'position u = 1.693718 * c: v = -1.693718 * s 'LEM vel. components gm = mgc / (rm * rm):aax = gm * s: aay = -gm * c 'grav acc tch = 10000: dch = .09 'horiz. thrust coeffs, dist. & vel. dcv = .06 'vert. thrust coeff, velocity damping st! = TIMER: xs = -180: tpm = 135: event = 1 'set timer DO: t = t + 1 'start main loop, 1 second intervals DO: LOOP UNTIL TIMER > st!: st! = TIMER + .03 'delay macc = thr / ml 'max. thrust acceleration available an = ATN(x / y): s =SIN(an): c =COS(an) 'angular position vv = v * c + u *s: hu = u *c - v *s 'vert & hor vel comps SELECT CASE event 'code peculiar to landing or take-off CASE 1: 'event 1 is the LANDING IF t = 300 THEN tch = 1000: IF h < 2 THEN dcv = .075 tcv = (500 - t)^2 / 13 + 500 'vert thrust control const var = (MRad - rm) / tcv - vv * dcv 'vert. acc. required har = (155 - x) / tch - hu * dch 'hor. acc. required cf = hu * hu / rm 'centrifugal acceleration vta = var + gm - cf 'vertical thrust acceleration ar2 = vta * vta + har * har: ar = SQR(ar2) 'total accel IF ar > macc THEN 'can't exceed max. thrust available har = -SQR(macc * macc - aty * aty): ml = ml - ff END IF 'hor. acc. sacrificed. Vert. acc. ensured IF ar macc THEN vta=macc -.00001 'vert. thrust limited hta = SQR(macc * macc - vta * vta) 'hor. thrust accel. atx = hta * c + vta * s: aty = vta * c - hta * s ang = ATN(aty / atx) 'thrust acc. components & angle END SELECT 'NOW for code common to both events u = u + aax: v = v + aay '1 second increment to velocity x = x + u: y = y + v '1 second increment to position rm2 = x * x + y * y: rm = SQR(rm2) 'radius to moon centre gm = mgc / rm2 'gravitational acceleration w2 = u * u + v * v: w = SQR(w2) 'total velocity E = w2 / 2 - mgc / rm 'total specific energy gmx = -gm * x / rm: gmy = -gm * y / rm 'grav. components aax = gmx + atx: aay = gmy + aty 'nett accel. components IF t MOD 5 = 0 THEN 'every 5 seconds, plot things angc = angc + cw5: xc = CMR * SIN(angc) 'CM angle yc = CMR * COS(angc): PSET (xc, yc), 7 'plot position h = rm - 1738: tp = t * .3 - tpm 'height. x plot pos. PSET (tp, 1720 + E * 30), 4: PSET (tp, w * 50 + 1620), 2 PSET (tp, ml * .005 + 1620), 3 'energy, velocity, mass, PSET (tp, ang * 57.3 + 1620), 7 'and angle to horiz. PSET (x, y), 7 'LEM position. Thrust line (for red fan) LINE (-50, 1690)-STEP(atx * 20000, aty * 20000), 4 LINE (70, 1680)-STEP(0, -20000 * gm2), 0 'blot out... LINE STEP(-2, 0)-STEP(0, 20000 * cf2), 0 'acc. polygon LINE -STEP(atx2 * 20000, aty2 * 20000), 0 ' " LINE (70, 1680)-STEP(u2 * 50, v2 * 50), 0 ' " LINE (70, 1680)-STEP(0, -20000 * gm), 7 'draw grav. acc. LINE STEP(-2, 0)-STEP(0, 20000 * cf), 5 'centrif. acc., LINE -STEP(atx * 20000, aty * 20000), 4 'thrust acc., LINE (70, 1680)-STEP(u * 50, v * 50), 2 'and velocity gm2 = gm: cf2 = cf: atx2 = atx 'remember for blotting... aty2 = aty: u2 = u: v2 = v '...out on next loop IF t MOD 60 = 5 THEN 'every min. plot polygon at bottom xs = xs + 40 'included mainly for magazine Fig 7 & 8 LINE (xs, 1590)-STEP(0, -20000 * gm), 7'draw grav. acc. LINE STEP(-2, 0)-STEP(0, 20000 * cf), 5 'centrif. acc., LINE -STEP(atx * 20000, aty * 20000), 4 'thrust acc., LINE (xs, 1590)-STEP(u * 50, v * 50), 2 'and velocity END IF: 'COLOR 4 'PRINT t;w;"km / sec ";h;" km ";CINT(mli -ml); "kg fuel" K$ = INKEY$: IF K$ = CHR$(27) OR K$ = "q" THEN END IF event = 1 THEN 'just for LANDING IF t > 400 THEN 'plot final phase in inset xt = x * 20 - 3000: yt = 1770 + h * 20 'position LINE (xt, yt)-(100, 1770), 7: FOR i = 1 TO 10000: NEXT LINE (xt, yt)-(100, 1770), 0: PSET (xt, yt), 7 END IF 'line flashes between LEM and landing target IF t = 400 THEN DrawLEM1 -88, 1820 'daggy schematics IF t = 450 THEN DrawLEM2 50, 1810 IF h < .001 THEN 'LEM has landed DrawLEM2 140, 1790: DrawLEM2 180, 1750 'schematics 'PRINT "The Eagle has landed. 2.17 PM.(Florida time). 'DO: LOOP WHILE INKEY$ = "" 'PRINT "Astronauts emerge at 10.56 PM for 2 hr EVA" 'PRINT "Take-off was at 1.54 PM the next day." DO: LOOP WHILE INKEY$ = "" 'Pause to read Picture (2) 'redraw screen for take-off 'PRINT "Ascent stage took off 70 secs after CM/SM had" 'PRINT "passed. Mass 4.5 tonnes, thrust 1.364 tonnes." 'DO: LOOP WHILE INKEY$ = "" 'Pause to read angc = -.1: ml = 4500 'Ascent module position & mass tl = 1364: thr = tl * .0098: mli = ml 'thrust & accel. ff = tl /SI: t =0: h =0 'fuel flow. Zero time & height rm = 1738: s = SIN(angc): c = COS(angc) 'moon radius x = rm * s: y = rm * c: u = -.005: v = 0 'pos. & vel. gm = mgc / (rm * rm): aax = 0: aay = 0 'grav. accel. DO: t = t + 5 'CM/SM travels 70 seconds ahead angc = angc + cw5 'each 5 sec, increment angle and... PSET (CMR * SIN(angc), CMR * COS(angc)), 7 'plot it LOOP UNTIL t = 70 'Now ascent module can go 'PRINT "Time for take-off.": DO:LOOP WHILE INKEY$ = "" LINE (-187, 1776)-(-173, 1761), 0, BF 'daggy schematic LINE (-186, 1801)-(-174, 1791), 7, B LINE (-182, 1791)-(-184, 1787), 7 LINE (-178, 1791)-(-176, 1787), 7 LINE (-184, 1787)-(-176, 1770), 4, BF rm1 = 1754: rm2 = 1821 'initial perilune & apolune rv2 = 9794 * rm2 / (rm1 * (rm1 + rm2)) 'required vel^2 Er = rv2 / 2 - mgc / rm1 'total spec. energy required event = 2: xs = -200 'now use take-off code END IF 'end of IF h < .001 .... END IF 'end of IF event = 1 .... IF event = 2 AND t < 250 THEN 'plot in inset PSET (x * 10 + 1650, 1770 + h * 10), 7 END IF END IF 'end of IF t MOD 5 = 0 .... IF event = 2 AND E > Er THEN EXIT DO'has energy for orbit LOOP rn = SQR((xc - x) ^ 2 + (yc - y) ^ 2) 'distance AM to CM angc =ATN(xc / yc): an = ATN(x / y) 'CM/AM angle positions 'PRINT "Ascent module at 18 km alt. in 16 by 83 km orbit." 'PRINT "Fuel burnt"; CINT(mli - ml); "kg. CM is "; PRINT CINT(rn); "km ahead." LINE (160, 1756)-(170, 1744), 7, B 'daggy schematic LINE(154,1754)-(160,1752),7:LINE(154, 1746)-(160, 1748), 7 DO: LOOP WHILE INKEY$ = "" ` END OF CODE LISTING 5. Continued in Listing 5a. Listing 5a SUB DrawLEM1 (x, y) LINE(x,y-6)-STEP(-10,12),7,B: LINE(x,y -9)-STEP(15, 18), 7, B LINE(x +8,y -9)-STEP(13,-9),7: LINE(x +8,y +9)-STEP(13, 9), 7 LINE(x +15,y -8)-STEP(2,-8),7: LINE(x +15,y +8)-STEP(2, 8), 7 LINE(x +15,y -4)-STEP(3,-2),7: LINE(x +15,y +4)-STEP(3, 2), 7 LINE(x+18,y-6)-(x+40,y+ 6),4,BF END SUB SUB DrawLEM2 (x, y) LINE (x+6,y)-STEP(-12,10),7, B:LINE(x-9,y)-STEP(18,-15), 7, B LINE (x-9,y-8)-STEP(-9,-13),7: LINE(x+9,y- 8)-STEP(9,-13), 7 LINE (x-16,y-17)-STEP(8,2),7: LINE(x+16,y- 17)-STEP(-8, 2), 7 LINE (x -6,y -18)-STEP(2,3),7: LINE(x +6,y -18)-STEP(-2,3), 7 IF x = 50 THEN LINE (x - 6, y - 17)-STEP(12, -23), 4, BF END SUB SUB Picture (pic) 'draws sene for landig or take off WINDOW (-200, 1550)-(200, 1850): CLS : VIEW PRINT COLOR 2: LOCATE 14: PRINT " 2": PRINT " V" PRINT " e": PRINT " l": PRINT " o" PRINT " c 1": PRINT " i": PRINT " t" PRINT " y": PRINT : PRINT " 0": COLOR 4:LOCATE 16 PRINT "E":PRINT "n":PRINT "e": PRINT "r": PRINT "g": PRINT "y" LOCATE 14, 5: PRINT "0": LOCATE 17, 4: PRINT "-1": LOCATE 20,4 PRINT "-2": LOCATE 23, 4: PRINT "-3": COLOR 3: LOCATE 14, 76 PRINT "20": LOCATE 19, 76: PRINT "10":LOCATE 16, 80: PRINT "W" LOCATE 17,80: PRINT "e": LOCATE 18,80: PRINT "i": LOCATE 19,80 PRINT "g": LOCATE 20, 80: PRINT "h": LOCATE 21, 80: PRINT "t" LOCATE 25: PRINT " 0 TIME 5 minutes 10" COLOR 15: LOCATE 15,69: PRINT "90 A": LOCATE 16,74:PRINT "n" LOCATE 17, 74: PRINT "g": LOCATE 19, 74: PRINT "H" LOCATE 20,74: PRINT "o": LOCATE 21,74: PRINT "r": LOCATE 24,70 PRINT "0": PSET (1738 * SIN(-.1), 1738 * COS(-.1)) FOR a=-.08 TO .1 STEP .02:LINE-(1738*SIN(a),1738*COS(a)):NEXT FOR yc=1630 TO 1720 STEP 30:LINE(-195,yc)-(-190,yc),4:NEXT 'En FOR yc=1620 TO 1720 STEP 50:LINE(-165,yc)-(-160,yc),2:NEXT'Vel FOR yc=1625 TO 1715 STEP 5:LINE(-165,yc)-(-163,yc),2:NEXT 'Vel FOR yc=1620 TO 1720 STEP 50:LINE(190,yc)-(185,yc),3:NEXT 'Wt FOR yc = 1625 TO 1715 STEP 5:LINE (190, yc)-(188, yc), 3: NEXT FOR yc = 1620 TO 1710 STEP 10:LINE(160,yc)-(155,yc),7:NEXT'Ang FOR xc=-132 TO 132 STEP 3:LINE(xc,1620)-(xc,1622),4:NEXT 'Time FOR xc = -117 TO 117 STEP 18: LINE (xc, 1620)-(xc,1625),4:NEXT FOR xc = -135 TO 135 STEP 90: LINE (xc, 1620)-(xc,1630),4:NEXT IF pic = 1 THEN 'draw scene for landing DrawLEM1 -180, 1760 'draw approaching LEM LOCATE 2, 50: PRINT "Inset 4 km X 13 km": LOCATE 28 PRINT "LEM at perilune retrofires. CM/SM in orbit overhead." PRINT "LEM weighs 14.7 tonnes, thrust is 4.5 tonnes. Key." ELSE 'draw LEM ready for take-off DrawLEM2 -180, 1760: LOCATE 2, 50: PRINT "Inset 20 km X 7 km" END IF 'draw inset LINE(-100,1841)-(170,1760),4,B: LINE(-100,1770)-(170,1770) , 1 LINE (-170, 1824)-STEP(15, 12), 7, B 'draw CM/SM overhead LINE(-180,1825)-STEP(10,2),7: LINE(-180, 1835)-STEP(10, -2), 7 LINE (-155, 1824)-STEP(12, 5), 7 LINE -STEP(0, 2), 7:LINE -STEP(-12, 5), 7: VIEW PRINT 28 TO 30 DO: LOOP WHILE INKEY$ = "" END SUB