Skip to content

Instantly share code, notes, and snippets.

@shiffman
Last active August 29, 2023 15:57
Show Gist options
  • Save shiffman/8efaacc24625ec436701db221b24e356 to your computer and use it in GitHub Desktop.
Save shiffman/8efaacc24625ec436701db221b24e356 to your computer and use it in GitHub Desktop.
AppleSoft BASIC 3D Cube
10 REM POKE 230,32 : REM page 1
20 REM POKE 230,64 : REM page 2
30 REM POKE 49236,0 : REM display page 1
40 REM POKE 49237,0 : REM display page 2
100 HGR:HGR2
105 W = 140 : H = 90 : SL = 50
110 TH = 0
120 SCR = 0
125 GOSUB 1000
130 GOSUB 5400
135 GOSUB 7000
140 GOSUB 5100
155 TH = TH + 0.05
170 GOTO 130
1000 DIM PTS(8,3)
1005 DIM RZT(8,3)
1006 DIM RYT(8,3)
1007 DIM RXT(8,3)
1020 PTS(0,0) = -1 : PTS(0,1) = -1 : PTS(0,2) = -1
1030 PTS(1,0) = 1 : PTS(1,1) = -1 : PTS(1,2) = -1
1040 PTS(2,0) = 1 : PTS(2,1) = 1 : PTS(2,2) = -1
1050 PTS(3,0) = -1 : PTS(3,1) = 1 : PTS(3,2) = -1
1060 PTS(4,0) = -1 : PTS(4,1) = -1 : PTS(4,2) = 1
1070 PTS(5,0) = 1 : PTS(5,1) = -1 : PTS(5,2) = 1
1080 PTS(6,0) = 1 : PTS(6,1) = 1 : PTS(6,2) = 1
1090 PTS(7,0) = -1 : PTS(7,1) = 1 : PTS(7,2) = 1
1100 RETURN
5100 REM DRAW SQUARE
5110 HCOLOR=3
5120 A = 0 : B = 1 : GOSUB 6000
5130 A = 1 : B = 2 : GOSUB 6000
5140 A = 2 : B = 3 : GOSUB 6000
5150 A = 3 : B = 0 : GOSUB 6000
5160 A = 4 : B = 5 : GOSUB 6000
5170 A = 5 : B = 6 : GOSUB 6000
5180 A = 6 : B = 7 : GOSUB 6000
5190 A = 7 : B = 4 : GOSUB 6000
5200 A = 0 : B = 4 : GOSUB 6000
5210 A = 1 : B = 5 : GOSUB 6000
5220 A = 2 : B = 6 : GOSUB 6000
5230 A = 3 : B = 7 : GOSUB 6000
5240 RETURN
5400 REM SWAP SCREENS
5410 SCR = NOT SCR
5420 POKE 49236+(NOT SCR),0 : REM SHOW OTHER PAGE
5430 POKE 230,32*(SCR+1) : REM SWITCH TO THIS PAGE
5440 CALL 62450
5470 RETURN
6000 X1 = SL * RYX(A,0) + W : Y1 = SL * RYX(A,1) + H
6010 X2 = SL * RYX(B,0) + W : Y2 = SL * RYX(B,1) + H
6020 HPLOT X1,Y1 TO X2,Y2
6030 RETURN
7000 CS = COS(TH) : SN = SIN(TH)
7005 FOR I = 0 TO 8
7010 RZT(I,0) = CS * PTS(I,0) - SN * PTS(I,1) + 0 * PTS(I,2)
7020 RZT(I,1) = SN * PTS(I,0) + CS * PTS(I,1) + 0 * PTS(I,2)
7030 RZT(I,2) = 0 * PTS(I,0) + 0 * PTS(I,1) + 1 * PTS(I,2)
7040 RYT(I,0) = CS * RZT(I,0) + 0 * RZT(I,1) + SN * RZT(I,2)
7050 RYT(I,1) = 0 * RZT(I,0) + 1 * RZT(I,1) + 0 * RZT(I,2)
7060 RYT(I,2) = -SN * RZT(I,0) + 0 * RZT(I,1) + CS * RZT(I,2)
7070 RYX(I,0) = 1 * RYT(I,0) + 0 * RYT(I,1) + 0 * RYT(I,2)
7080 RYX(I,1) = 0 * RYT(I,0) + CS * RYT(I,1) + SN * RYT(I,2)
7090 RYX(I,2) = 0 * RYT(I,0) + SN * RYT(I,1) + CS * RYT(I,2)
7100 NEXT I
7200 RETURN
@yrockett
Copy link

Is there any Apple Emulator that can run this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment