Program: Slinshot.bas
Implementation Select: Implementation
Operation Select: Program: SLINSHOT.BAS
DECLARE SUB GETANGLE (x#, y#, angle#)
DEFDBL A-Z
' SLINSHOT.BAS
' Revision 1.0 27 Dec 1996
' Revision 2.0 27 Feb 2000
CONST pi = 3.141592653589#
CONST rad = 180 / pi
CONST esc = 27, ENTER = 13
SCREEN 12
SL1:
CLS
sstep = 0
h = .002
m1 = 100000: m2 = 100
x1 = 200: y1 = 100:
r2 = 100: v2 = -SQR(m1 / r2): v2str = ABS(v2) ' circle speed
COLOR 7: PRINT "Select between speed up or speed down"
COLOR 15: INPUT "Sling shot speed up ? (Y or N) ", a$
IF UCASE$(a$) = "N" THEN
alp2 = 99.8
delta = -.2
mesg1$ = "Speed Down"
ELSE
alp2 = 99.2 ' start angle m2
delta = .2
mesg1$ = "Speed Up"
END IF
COLOR 7: PRINT "Select between small scale or large scale effect"
mesg3$ = "Small Scale "
COLOR 15: INPUT "Small scale effect ?(Y or N) ", a$
IF UCASE$(a$) = "N" THEN alp2 = alp2 + delta: mesg3$ = "Large Scale"
COLOR 7: PRINT "Select between Slow or Fast update"
COLOR 15: INPUT "Slow update ? (Y or N) ", a$
slow = 1 ' slow
IF UCASE$(a$) = "N" THEN slow = 0 ' fast
COLOR 7: PRINT "Select mass of m3 = 0 or = 20 "
COLOR 15: INPUT "Mass of m3 = 0 ? (Y or N) ", a$
m3 = 0 ' small
IF UCASE$(a$) = "N" THEN m3 = 20 ' large
PRINT
PRINT "Select S for Single Step mode"
PRINT "Select ESC to terminate simulation"
PRINT "Select any key to start simulation"
DO:
a$ = INKEY$
IF a$ = CHR$(esc) THEN END
LOOP UNTIL a$ <> ""
dispcond = 20 ' inner loop count
h = h / dispcond ' update time
CLS
LOCATE 1, 1: PRINT "Sling shot "; mesg1$; SPACE$(3); mesg3$; SPACE$(12); "Mass m3 ="; m3
x2 = x1 + r2 * COS(alp2 * pi / 180): y2 = y1 + r2 * SIN(alp2 * pi / 180)
v2x = v2 * COS((alp2 + 90) * pi / 180): v2y = v2 * SIN((alp2 + 90) * pi / 180)
r3 = 100
x3 = x1: y3 = y1 + .75 * r3
dx = x1 - x3: dy = y1 - y3
rr2 = dx * dx + dy * dy: r = SQR(rr2)
v3 = SQR(2 * m1 / r): v3str = ABS(v3) ' escape speed
v3x = 0: v3y = v3
v1x = 0: v1y = 0:
LOCATE 7, 1: COLOR 12: PRINT "v3 as f of escape velocity"
LOCATE 19, 1: COLOR 15: PRINT "v2 of m2"
LOCATE 17, 63: COLOR 13: PRINT "distance m2,m3"
LOCATE 24, 1: COLOR 14: PRINT "v3 of m3"
LOCATE 28, 46: COLOR 6: PRINT "m1"
LOCATE 14, 56: COLOR 15: PRINT "m2"
LOCATE 10, 47: COLOR 14: PRINT "m3"
mulc = 3.8
CIRCLE (x1 * mulc - 390, 805 - y1 * mulc), 2, 6 'm1
time1 = TIMER: time2 = time1
FOR j = 1 TO 625
FOR i = 1 TO dispcond
dx = x1 - x2: dy = y1 - y2
r2 = dx * dx + dy * dy: r = SQR(r2)
a12x = dx / (r * r2): a12y = dy / (r * r2)
v2x = v2x + a12x * m1 * h: v2y = v2y + a12y * m1 * h
dx = x1 - x3: dy = y1 - y3
GETANGLE -dx, -dy, alpr
r2 = dx * dx + dy * dy: r = SQR(r2)
a13x = dx / (r * r2): a13y = dy / (r * r2)
v3x = v3x + a13x * m1 * h: v3y = v3y + a13y * m1 * h
dx = x2 - x3: dy = y2 - y3
r2 = dx * dx + dy * dy: r = SQR(r2)
a23x = dx / (r * r2): a23y = dy / (r * r2)
v2x = v2x - a23x * m3 * h: v2y = v2y - a23y * m3 * h
v3x = v3x + a23x * m2 * h: v3y = v3y + a23y * m2 * h
GETANGLE v3x, v3y, alpv
x2 = x2 + v2x * h: y2 = y2 + v2y * h
x3 = x3 + v3x * h: y3 = y3 + v3y * h
NEXT i
cnt = j
COLOR 15
LOCATE 1, 75: PRINT cnt
PSET (x2 * mulc - 390, 980 - y2 * mulc), 15
PSET (x3 * mulc - 390, 980 - y3 * mulc), 14
mulc1 = 32
PSET (mulc1 * (x2 - 190), (206 - y2) * mulc1), 15
PSET (mulc1 * (x3 - 190), (206 - y3) * mulc1), 14
PSET (cnt, 305 - (SQR(v2x * v2x + v2y * v2y) - v2str) * 8), 15
PSET (cnt, 305 - (SQR(v3x * v3x + v3y * v3y) - v3str) * 8), 14
PSET (cnt, 305 - 2 * r), 13 ' dist x2-x3
dx = x1 - x3: dy = y1 - y3
r2 = dx * dx + dy * dy: r = SQR(r2)
v3 = SQR(v3x * v3x + v3y * v3y)
vrad = v3 * COS((alpr - alpv) / rad)
'PRINT v3, vrad: END
PSET (cnt, 290 - vrad / SQR(2 * m1 / r) * 200), 12
PSET (cnt, 290 - 1 * 200), 12
IF slow = 1 THEN
DO
LOOP UNTIL TIMER <> time1
END IF
time1 = TIMER
DO
a$ = INKEY$
IF a$ = CHR$(esc) THEN END
IF UCASE$(a$) = "S" THEN
IF sstep = 0 THEN
sstep = 1: a$ = "x" ' Start Single step
LOCATE 1, 50: COLOR 5: PRINT "Single Step Mode"
ELSE
a$ = "" ' Perform one step
END IF
ELSE
IF sstep = 1 THEN
IF a$ <> "" THEN
sstep = 0: a$ = ""
LOCATE 1, 50: PRINT SPACE$(16) ' End S Step mode
ELSE
a$ = "x" ' Wait
END IF
ELSE
a$ = "" ' No action
END IF
END IF
LOOP UNTIL UCASE$(a$) = ""
NEXT j
COLOR 7
dx = x1 - x3: dy = y1 - y3
r2 = dx * dx + dy * dy: r = SQR(r2)
PRINT USING "v3 str ####.##"; v3str
PRINT USING "v3 end ####.##"; SQR(v3x * v3x + v3y * v3y)
PRINT USING "v3 escape ####.##"; SQR(2 * m1 / r)
PRINT USING "start angle m2 ####.##"; alp2:
DO:
a$ = INKEY$
IF a$ = CHR$(esc) THEN END
LOOP UNTIL a$ <> ""
GOTO SL1
SUB GETANGLE (x, y, angle)
IF x <> 0 THEN
angle = ATN(y / x) * rad
IF x < 0 THEN
angle = angle + 180
ELSE
IF y < 0 THEN
angle = angle + 360
END IF
END IF
ELSE
IF y > 0 THEN
angle = 90
ELSE
angle = 270
END IF
END IF
END SUB
Back to my home page Contents of This Document