Add five mathematics and physics programs

This commit is contained in:
Christian Johannesen 2026-10-22 11:25:15 +02:00
parent aded9ae256
commit 36e8f50149
12 changed files with 201 additions and 1 deletions

View file

@ -1,6 +1,6 @@
# C64 Program Collection # C64 Program Collection
Thirty-three small, polished programs for the Commodore 64, written in stock Commodore BASIC V2 and 6502 machine code. The collection mixes arcade action, puzzles, simulations, creative tools, music, utilities, and visual effects. Every entry is self-contained and runs on an ordinary PAL or NTSC C64 without a cartridge or BASIC extension. Thirty-eight small, polished programs for the Commodore 64, written in stock Commodore BASIC V2 and 6502 machine code. The collection mixes arcade action, puzzles, simulations, mathematics, physics, creative tools, music, utilities, and visual effects. Every entry is self-contained and runs on an ordinary PAL or NTSC C64 without a cartridge or BASIC extension.
Browse and run the collection at [c64.p20.dev](https://c64.p20.dev). Browse and run the collection at [c64.p20.dev](https://c64.p20.dev).
@ -41,6 +41,11 @@ Browse and run the collection at [c64.p20.dev](https://c64.p20.dev).
| Plasma Grid | 2026-10-16 | Demo | Machine Code | `1`-`3`, `C`, Space, `Q` | Fill the screen with a flowing field of color generated in real time. | [ASM](plasma-grid/plasma-grid.asm) | [Run](https://c64.p20.dev/program/plasma-grid) | | Plasma Grid | 2026-10-16 | Demo | Machine Code | `1`-`3`, `C`, Space, `Q` | Fill the screen with a flowing field of color generated in real time. | [ASM](plasma-grid/plasma-grid.asm) | [Run](https://c64.p20.dev/program/plasma-grid) |
| Neon Rift | 2026-10-16 | Demo | Machine Code | `1`-`3`, `C`, `M`, Space, `Q` | Enter a neon-colored world of orbiting sprites, a scrolling message, and a three-voice SID score. | [ASM](neon-rift/neon-rift.asm) | [Run](https://c64.p20.dev/program/neon-rift) | | Neon Rift | 2026-10-16 | Demo | Machine Code | `1`-`3`, `C`, `M`, Space, `Q` | Enter a neon-colored world of orbiting sprites, a scrolling message, and a three-voice SID score. | [ASM](neon-rift/neon-rift.asm) | [Run](https://c64.p20.dev/program/neon-rift) |
| Infinite Road | 2026-10-21 | Demo | Machine Code | `A`, `D`, `1`-`3`, `C`, `M`, Space, `Q` | Cruise along an endless synthwave highway with sweeping curves and a driving three-voice SID score. | [ASM](infinite-road/infinite-road.asm) | [Run](https://c64.p20.dev/program/infinite-road) | | Infinite Road | 2026-10-21 | Demo | Machine Code | `A`, `D`, `1`-`3`, `C`, `M`, Space, `Q` | Cruise along an endless synthwave highway with sweeping curves and a driving three-voice SID score. | [ASM](infinite-road/infinite-road.asm) | [Run](https://c64.p20.dev/program/infinite-road) |
| Projectile Lab | 2026-10-22 | Physics | BASIC | `5`-`30`, `10`-`80`, `R`, `Q` | Plot a projectile's flight from launch speed and angle. | [BAS](projectile-lab/projectile-lab.bas) | [Run](https://c64.p20.dev/program/projectile-lab) |
| Prime Workshop | 2026-10-22 | Mathematics | BASIC | `2`-`9999`, Return, Space, `Q` | Factor whole numbers and calculate divisor counts and Euler's totient. | [BAS](prime-workshop/prime-workshop.bas) | [Run](https://c64.p20.dev/program/prime-workshop) |
| Pi Drop | 2026-10-22 | Mathematics | BASIC | Space, `Q` | Estimate pi by dropping random coordinates into a virtual unit circle. | [BAS](pi-drop/pi-drop.bas) | [Run](https://c64.p20.dev/program/pi-drop) |
| Wave Composer | 2026-10-22 | Physics | BASIC | `A`, `Z`, `S`, `X`, Space, `Q` | Combine two sine waves and watch interference reshape the graph. | [BAS](wave-composer/wave-composer.bas) | [Run](https://c64.p20.dev/program/wave-composer) |
| Orbit Lab | 2026-10-22 | Physics | BASIC | `1`-`3`, `T`, `R`, Space, `Q` | Explore how velocity and gravity shape a simple two-dimensional orbit. | [BAS](orbit-lab/orbit-lab.bas) | [Run](https://c64.p20.dev/program/orbit-lab) |
## Running the programs ## Running the programs

36
orbit-lab/orbit-lab.bas Normal file
View file

@ -0,0 +1,36 @@
10 GOSUB 9000
100 G=50:T=1:GOSUB 500
110 PRINT CHR$(147):PRINT "ORBIT LAB GRAVITY";G;" 1/2/3"
120 PRINT "T=TRAIL SPACE=PAUSE R=RESET Q=QUIT"
130 IF T=1 THEN 140
135 O=1024+INT(12+Y)*40+INT(20+X):IF O>=1024 AND O<2024 THEN POKE O,32
140 R=SQR(X*X+Y*Y):IF R<2 OR R>19 THEN GOSUB 500:GOTO 130
150 AX=-G*X/(R*R*R):AY=-G*Y/(R*R*R)
160 VX=VX+AX*.08:VY=VY+AY*.08:X=X+VX*.08:Y=Y+VY*.08
170 POKE 1024+12*40+20,42:POKE 55296+12*40+20,7
180 P=1024+INT(12+Y)*40+INT(20+X)
190 IF P>=1024 AND P<2024 THEN POKE P,81:POKE P+54272,3
200 GET A$:IF A$="1" THEN G=35
210 IF A$="2" THEN G=50
220 IF A$="3" THEN G=70
230 IF A$="T" THEN T=1-T
250 IF A$="R" THEN GOSUB 500
260 IF A$=" " THEN GOSUB 600
270 IF A$<>"Q" THEN 130
280 GOTO 9900
500 X=12:Y=0:VX=0:VY=2.05:RETURN
600 GET A$:IF A$="" THEN 600
610 IF A$="Q" THEN 9900
620 RETURN
9000 POKE 53280,0:POKE 53281,0:PRINT CHR$(147);CHR$(154)
9010 PRINT:PRINT:PRINT " ORBIT LAB":PRINT
9020 PRINT CHR$(5);" WATCH VELOCITY BEND AROUND GRAVITY":PRINT:PRINT
9030 PRINT CHR$(153);" CONTROLS":PRINT
9040 PRINT CHR$(158);" 1-3";CHR$(5);" GRAVITY ";CHR$(158);"T";CHR$(5);" TRAIL ";CHR$(158);"R";CHR$(5);" RESET"
9050 PRINT " ";CHR$(158);"SPACE";CHR$(5);" PAUSE ";CHR$(158);"Q";CHR$(5);" QUIT":PRINT:PRINT
9060 PRINT " HTTPS://C64.P20.DEV":PRINT
9070 PRINT CHR$(152);" RELEASED 22 OCTOBER 2026":PRINT:PRINT
9080 PRINT CHR$(158);" PRESS SPACE TO START"
9090 GET A$:IF A$<>" " THEN 9090
9100 RETURN
9900 POKE 53280,14:POKE 53281,6:PRINT CHR$(147):END

BIN
orbit-lab/orbit-lab.prg Normal file

Binary file not shown.

27
pi-drop/pi-drop.bas Normal file
View file

@ -0,0 +1,27 @@
10 GOSUB 9000
100 R=RND(-TI):N=0:H=0:PRINT CHR$(147)
110 FOR Y=3 TO 22:FOR X=1 TO 38:POKE 1024+Y*40+X,32:NEXT:NEXT
120 X=RND(1)*2-1:Y=RND(1)*2-1:N=N+1:Z=X*X+Y*Y
130 C=1+INT((X+1)*18.5):Q=3+INT((Y+1)*9.5):IF C>38 THEN C=38
140 IF Q>22 THEN Q=22
150 P=1024+Q*40+C:POKE P,46
160 IF Z<=1 THEN H=H+1:POKE P+54272,5:GOTO 180
170 POKE P+54272,10
180 IF N/20<>INT(N/20) THEN 210
190 E=4*H/N:PRINT CHR$(19);"PI DROP SAMPLES";N;" PI";INT(E*10000)/10000
200 PRINT "GREEN=INSIDE RED=OUTSIDE"
210 GET A$:IF A$=" " THEN 100
220 IF A$<>"Q" THEN 120
230 GOTO 9900
9000 POKE 53280,0:POKE 53281,0:PRINT CHR$(147);CHR$(154)
9010 PRINT:PRINT:PRINT " PI DROP":PRINT
9020 PRINT CHR$(5);" ESTIMATE PI WITH RANDOM COORDINATES":PRINT:PRINT
9030 PRINT CHR$(153);" CONTROLS":PRINT
9040 PRINT CHR$(158);" SPACE";CHR$(5);" RESET THE EXPERIMENT"
9050 PRINT " ";CHR$(158);"Q";CHR$(5);" QUIT":PRINT:PRINT
9060 PRINT " HTTPS://C64.P20.DEV":PRINT
9070 PRINT CHR$(152);" RELEASED 22 OCTOBER 2026":PRINT:PRINT
9080 PRINT CHR$(158);" PRESS SPACE TO START"
9090 GET A$:IF A$<>" " THEN 9090
9100 RETURN
9900 POKE 53280,14:POKE 53281,6:PRINT CHR$(147):END

BIN
pi-drop/pi-drop.prg Normal file

Binary file not shown.

View file

@ -0,0 +1,39 @@
10 GOSUB 9000
100 PRINT CHR$(147):PRINT " PRIME WORKSHOP":PRINT
110 INPUT "NUMBER 2-9999 (0 QUITS)";N
120 IF N=0 THEN 9900
130 IF N<2 OR N>9999 OR N<>INT(N) THEN PRINT "WHOLE NUMBERS ONLY.":GOTO 110
140 M=N:P=2:F$="":C=0:D=1:T=N
150 IF P*P>M THEN 230
160 E=0
170 IF M/P<>INT(M/P) THEN 200
180 M=M/P:E=E+1:C=C+1:GOTO 170
200 IF E=0 THEN 220
210 GOSUB 500:D=D*(E+1):T=T-T/P
220 P=P+1:GOTO 150
230 IF M>1 THEN P=M:E=1:C=C+1:GOSUB 500:D=D*2:T=T-T/P
240 PRINT:PRINT "FACTORIZATION:":PRINT F$:PRINT
250 IF C=1 THEN PRINT N;"IS PRIME.":GOTO 270
260 PRINT N;"IS COMPOSITE."
270 PRINT "DIVISORS:";D
280 PRINT "EULER TOTIENT:";T
290 PRINT:PRINT "SPACE=ANOTHER Q=QUIT"
300 GET A$:IF A$=" " THEN 100
310 IF A$<>"Q" THEN 300
320 GOTO 9900
500 IF F$<>"" THEN F$=F$+" X "
510 F$=F$+MID$(STR$(P),2)
520 IF E>1 THEN F$=F$+"^"+MID$(STR$(E),2)
530 RETURN
9000 POKE 53280,0:POKE 53281,0:PRINT CHR$(147);CHR$(154)
9010 PRINT:PRINT:PRINT " PRIME WORKSHOP":PRINT
9020 PRINT CHR$(5);" FACTOR NUMBERS AND EXPLORE TOTIENTS":PRINT:PRINT
9030 PRINT CHR$(153);" CONTROLS":PRINT
9040 PRINT CHR$(158);" 2-9999";CHR$(5);" NUMBER ";CHR$(158);"RETURN";CHR$(5);" SOLVE"
9050 PRINT " ";CHR$(158);"SPACE";CHR$(5);" AGAIN ";CHR$(158);"Q";CHR$(5);" QUIT":PRINT:PRINT
9060 PRINT " HTTPS://C64.P20.DEV":PRINT
9070 PRINT CHR$(152);" RELEASED 22 OCTOBER 2026":PRINT:PRINT
9080 PRINT CHR$(158);" PRESS SPACE TO START"
9090 GET A$:IF A$<>" " THEN 9090
9100 RETURN
9900 POKE 53280,14:POKE 53281,6:PRINT CHR$(147):END

Binary file not shown.

View file

@ -196,5 +196,35 @@
"description": "Cruise along an endless synthwave highway with sweeping curves and a driving three-voice SID score.", "description": "Cruise along an endless synthwave highway with sweeping curves and a driving three-voice SID score.",
"controls": [{"keys":["A","D"],"description":"Shift the viewpoint left or right"},{"keys":["1","2","3"],"description":"Select slow, medium, or fast cruising speed"},{"keys":["C"],"description":"Change the color palette"},{"keys":["M"],"description":"Mute or restore the SID track"},{"keys":["SPACE"],"description":"Pause or resume the demo"},{"keys":["Q"],"description":"Return to BASIC"}], "controls": [{"keys":["A","D"],"description":"Shift the viewpoint left or right"},{"keys":["1","2","3"],"description":"Select slow, medium, or fast cruising speed"},{"keys":["C"],"description":"Change the color palette"},{"keys":["M"],"description":"Mute or restore the SID track"},{"keys":["SPACE"],"description":"Pause or resume the demo"},{"keys":["Q"],"description":"Return to BASIC"}],
"path": "infinite-road/infinite-road.prg", "source": "infinite-road/infinite-road.asm" "path": "infinite-road/infinite-road.prg", "source": "infinite-road/infinite-road.asm"
},
{
"title": "Projectile Lab", "category": "Physics", "language": "basic", "releaseDate": "2026-10-22",
"description": "Plot a projectile's flight from launch speed and angle.",
"controls": [{"keys":["5-30"],"description":"Choose launch speed"},{"keys":["10-80"],"description":"Choose launch angle"},{"keys":["R"],"description":"Launch again"},{"keys":["Q"],"description":"Quit"}],
"path": "projectile-lab/projectile-lab.prg", "source": "projectile-lab/projectile-lab.bas"
},
{
"title": "Prime Workshop", "category": "Mathematics", "language": "basic", "releaseDate": "2026-10-22",
"description": "Factor whole numbers and calculate divisor counts and Euler's totient.",
"controls": [{"keys":["2-9999"],"description":"Enter a whole number"},{"keys":["RETURN"],"description":"Calculate"},{"keys":["SPACE"],"description":"Try another number"},{"keys":["Q"],"description":"Quit"}],
"path": "prime-workshop/prime-workshop.prg", "source": "prime-workshop/prime-workshop.bas"
},
{
"title": "Pi Drop", "category": "Mathematics", "language": "basic", "releaseDate": "2026-10-22",
"description": "Estimate pi by dropping random coordinates into a virtual unit circle.",
"controls": [{"keys":["SPACE"],"description":"Reset the experiment"},{"keys":["Q"],"description":"Quit"}],
"path": "pi-drop/pi-drop.prg", "source": "pi-drop/pi-drop.bas"
},
{
"title": "Wave Composer", "category": "Physics", "language": "basic", "releaseDate": "2026-10-22",
"description": "Combine two sine waves and watch interference reshape the graph.",
"controls": [{"keys":["A","Z"],"description":"Raise or lower wave one frequency"},{"keys":["S","X"],"description":"Raise or lower wave two frequency"},{"keys":["SPACE"],"description":"Pause or resume"},{"keys":["Q"],"description":"Quit"}],
"path": "wave-composer/wave-composer.prg", "source": "wave-composer/wave-composer.bas"
},
{
"title": "Orbit Lab", "category": "Physics", "language": "basic", "releaseDate": "2026-10-22",
"description": "Explore how velocity and gravity shape a simple two-dimensional orbit.",
"controls": [{"keys":["1","2","3"],"description":"Select gravity strength"},{"keys":["T"],"description":"Toggle the orbit trail"},{"keys":["R"],"description":"Reset the orbit"},{"keys":["SPACE"],"description":"Pause or resume"},{"keys":["Q"],"description":"Quit"}],
"path": "orbit-lab/orbit-lab.prg", "source": "orbit-lab/orbit-lab.bas"
} }
] ]

View file

@ -0,0 +1,30 @@
10 GOSUB 9000
100 PRINT CHR$(147):INPUT "LAUNCH SPEED (5-30)";V
110 IF V<5 OR V>30 THEN 100
120 INPUT "ANGLE (10-80 DEGREES)";A
130 IF A<10 OR A>80 THEN 120
140 R=A*3.14159265/180:G=9.8
150 D=V*V*SIN(2*R)/G:H=V*V*SIN(R)*SIN(R)/(2*G)
160 PRINT CHR$(147):PRINT "PROJECTILE LAB SPEED";V;" ANGLE";A
170 PRINT "RANGE";INT(D*10)/10;"M HEIGHT";INT(H*10)/10;"M"
180 FOR X=1 TO 38:POKE 1024+22*40+X,45:POKE 55296+22*40+X,12:NEXT
190 FOR I=0 TO 38:X=D*I/38:Y=X*TAN(R)-G*X*X/(2*V*V*COS(R)*COS(R))
200 IF Y<0 THEN Y=0
210 Q=21-INT(Y/H*17):IF Q<4 THEN Q=4
220 P=1024+Q*40+I+1:POKE P,42:POKE P+54272,7:NEXT
230 PRINT:PRINT "R=RELAUNCH Q=QUIT"
240 GET A$:IF A$="R" THEN 100
250 IF A$<>"Q" THEN 240
260 GOTO 9900
9000 POKE 53280,0:POKE 53281,0:PRINT CHR$(147);CHR$(154)
9010 PRINT:PRINT:PRINT " PROJECTILE LAB":PRINT
9020 PRINT CHR$(5);" PLOT A FLIGHT THROUGH GRAVITY":PRINT:PRINT
9030 PRINT CHR$(153);" CONTROLS":PRINT
9040 PRINT CHR$(158);" 5-30";CHR$(5);" SPEED ";CHR$(158);"10-80";CHR$(5);" ANGLE"
9050 PRINT " ";CHR$(158);"R";CHR$(5);" RELAUNCH ";CHR$(158);"Q";CHR$(5);" QUIT":PRINT:PRINT
9060 PRINT " HTTPS://C64.P20.DEV":PRINT
9070 PRINT CHR$(152);" RELEASED 22 OCTOBER 2026":PRINT:PRINT
9080 PRINT CHR$(158);" PRESS SPACE TO START"
9090 GET A$:IF A$<>" " THEN 9090
9100 RETURN
9900 POKE 53280,14:POKE 53281,6:PRINT CHR$(147):END

Binary file not shown.

View file

@ -0,0 +1,33 @@
10 GOSUB 9000
100 F1=2:F2=3:P=0:PRINT CHR$(147)
110 FOR Y=3 TO 22:FOR X=0 TO 39:POKE 1024+Y*40+X,32:NEXT:NEXT
120 PRINT CHR$(19);"WAVE COMPOSER F1";F1;" F2";F2
130 PRINT "A/Z=WAVE1 S/X=WAVE2 SPACE=PAUSE Q=QUIT"
140 FOR X=0 TO 39:Y=12+INT(4*SIN((X+P)*F1*.16)+3*SIN((X-P)*F2*.12))
150 IF Y<3 THEN Y=3
160 IF Y>22 THEN Y=22
170 Q=1024+Y*40+X:C=(X+P)-INT((X+P)/8)*8
175 POKE Q,42:POKE Q+54272,3+C:NEXT
180 P=P+1:GET A$
190 IF A$="A" AND F1<8 THEN F1=F1+1
200 IF A$="Z" AND F1>1 THEN F1=F1-1
210 IF A$="S" AND F2<8 THEN F2=F2+1
220 IF A$="X" AND F2>1 THEN F2=F2-1
230 IF A$=" " THEN GOSUB 400
240 IF A$<>"Q" THEN 110
250 GOTO 9900
400 GET A$:IF A$="" THEN 400
410 IF A$="Q" THEN 9900
420 RETURN
9000 POKE 53280,0:POKE 53281,0:PRINT CHR$(147);CHR$(154)
9010 PRINT:PRINT:PRINT " WAVE COMPOSER":PRINT
9020 PRINT CHR$(5);" MIX TWO SINE WAVES INTO ONE PATTERN":PRINT:PRINT
9030 PRINT CHR$(153);" CONTROLS":PRINT
9040 PRINT CHR$(158);" A/Z";CHR$(5);" WAVE 1 ";CHR$(158);"S/X";CHR$(5);" WAVE 2"
9050 PRINT " ";CHR$(158);"SPACE";CHR$(5);" PAUSE ";CHR$(158);"Q";CHR$(5);" QUIT":PRINT:PRINT
9060 PRINT " HTTPS://C64.P20.DEV":PRINT
9070 PRINT CHR$(152);" RELEASED 22 OCTOBER 2026":PRINT:PRINT
9080 PRINT CHR$(158);" PRESS SPACE TO START"
9090 GET A$:IF A$<>" " THEN 9090
9100 RETURN
9900 POKE 53280,14:POKE 53281,6:PRINT CHR$(147):END

Binary file not shown.