I wrote a 2D Gravity Simulator in BBC BASIC.
HTML-код
- Опубликовано: 28 авг 2024
- I`ve been trying to get this right for 40 years. I first tried it on a ZX Spectrum which took hours to run a simulation. The program is in the comments. Just download "BBC BASIC for Windows". Open it. Copy and Paste the program onto the page. Press the Green Arrow at the top and it will run.
i rem denny and you doing that about 40 yrs ago on my amiga at my place that takes me back lol
hahaha il just do this before i stop and this then that hahaha im the same you think i will stop now but your brain keeps working on the problem great video m8
It works better now I`ve got the gravity equation right. I forgot to times the distance by itself.
LET F=GC*((MA(N)*MA(M))/(C*C))
9 ON ERROR GOTO 165
10 DIM X(50)
20 DIM Y(50)
30 DIM XX(50)
40 DIM YY(50)
41 DIM XD(50)
42 DIM YD(50)
43 DIM XXD(50)
44 DIM YYD(50)
45 DIM MAD(50)
50 LET F=1
60 LET GC=1
70 DIM MA(50)
80 LET P=2 REM AMMOUNT OF PLANETS
90 LET A=0
100 LET B=0
110 COLOUR 1,15
120 COLOUR 2,0
130 GCOL 1
140 COLOUR 130
150 GCOL 130
160 COLOUR 1
165 CLS
170 *REFRESHON
171 CLS: INPUT TAB(10,10);"NUMBER OF PLANETS/STARS";P
172 CLS
173 PRINT TAB(5,2);"PLANET NUMBER X Y X SPEED Y SPEED MASS GRAVITY CONSTANT"
174 PRINT TAB(5,3);"============= ===== ===== ======= ======= ==== ================"
175 PRINT TAB(53,4);GC
176 FOR N=0 TO P-1
177 PRINT TAB(5,4+N);N+1
178 PRINT TAB(20,4+N);XD(N)
179 PRINT TAB(26,4+N);YD(N)
180 PRINT TAB(32,4+N);XXD(N)
182 PRINT TAB(40,4+N);YYD(N)
183 PRINT TAB(48,4+N);MAD(N)
184 NEXT N
185 PRINT TAB(5,5+P);"ENTER 0 TO RUN OR 99 TO CHANGE GAVITY CONSTANT"
186 INPUT TAB(5,6+P);"ADJUST PLANET NUMBER";PL: IF PL=0 THEN CLS: GOTO 300
187 IF PL=99 THEN INPUT TAB(5,7+P);"INPUT GRAVITY CONSTANT = ";GC:GOTO 172
194 INPUT TAB(5,7+P);"X = ";XD(PL-1)
195 INPUT TAB(5,8+P);"Y = ";YD(PL-1)
196 INPUT TAB(5,9+P);"X SPEED = ";XXD(PL-1)
197 INPUT TAB(5,10+P);"Y SPEED = ";YYD(PL-1)
198 INPUT TAB(5,11+P);"MASS = ";MAD(PL-1)
199 CLS: GOTO 173
300 FOR N=0 TO P-1
310 LET X(N)=XD(N)
311 LET Y(N)=YD(N)
312 LET XX(N)=XXD(N)
313 LET YY(N)=YYD(N)
314 LET MA(N)=MAD(N)
315 NEXT N
320 FOR N=0 TO P-1
321 FOR M=0 TO P-1
322 IF N=M THEN GOTO 330
325 IF X(N)=X(M) THEN LET X(N)=X(N)+0.0001: LET X(M)=X(M)-0.0001
326 IF Y(N)=Y(M) THEN LET Y(N)=Y(N)+0.0001:LET Y(M)=Y(M)-0.0001
330 NEXT M
331 NEXT N
380 REM *REFRESHON#
390 FOR N=0 TO P-1 REM DRAW THE PLANETS
395 LET SIZE=8+(MA(N))
400 CIRCLEFILL X(N),Y(N),SIZE
410 NEXT N
420 FOR N=0 TO P-1 REM MOVE THE PLANETS
430 LET X(N)=X(N)+XX(N)
440 LET Y(N)=Y(N)+YY(N)
450 NEXT N
460 FOR N=0 TO P-1 REM CALCULATE DISTANCE BETWEEN PLANETS AND CALCULATE GRAVITY FORCE
470 FOR M=0 TO P-1
480 IF N=M THEN GOTO 690
490 IF X(N)>X(M) THEN LET A=X(N)-X(M) REM WORK OUT TRIANGLE "A" SIDE
500 IF X(N)Y(M) THEN LET B=Y(N)-Y(M) REM WORK OUT TRIANGLE "B" SIDE
520 IF Y(N)X(M) AND Y(N)>Y(M) THEN LET CO=CO+PI: LET SI=SI+PI REM ADJUST THE ANGLE 180 DEGREES
590 IF X(N)Y(M) THEN LET SI=SI+PI
600 IF X(N)>X(M) AND Y(N)