Created
December 31, 2025 14:12
-
-
Save kevingosse/170e5f8e0ccd12cc0db0c63ab4eb85e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' Turbo Basic (Borland 1987) version of rotating cube | |
| ' ESC to quit | |
| W% = 320 | |
| H% = 200 | |
| NBPOINTS% = 8 | |
| SCREEN 1 | |
| CLS | |
| DIM lines%(1:6, 1:4) | |
| DIM linelen%(1:6) | |
| DIM px!(1:NBPOINTS%) | |
| DIM py!(1:NBPOINTS%) | |
| DIM pz!(1:NBPOINTS%) | |
| ' Cube points | |
| DATA 0.25, 0.25, 0.25 | |
| DATA -0.25, 0.25, 0.25 | |
| DATA -0.25, -0.25, 0.25 | |
| DATA 0.25, -0.25, 0.25 | |
| DATA 0.25, 0.25, -0.25 | |
| DATA -0.25, 0.25, -0.25 | |
| DATA -0.25, -0.25, -0.25 | |
| DATA 0.25, -0.25, -0.25 | |
| FOR i% = 1 TO NBPOINTS% | |
| READ px!(i%) | |
| READ py!(i%) | |
| READ pz!(i%) | |
| NEXT i% | |
| ' Faces/edges as loops: count then indices (0-based in data, we +1 after read) | |
| DATA 4, 0,1,2,3 | |
| DATA 4, 4,5,6,7 | |
| DATA 2, 0,4 | |
| DATA 2, 1,5 | |
| DATA 2, 2,6 | |
| DATA 2, 3,7 | |
| FOR i% = 1 TO 6 | |
| READ linelen%(i%) | |
| FOR j% = 1 TO linelen%(i%) | |
| READ lines%(i%, j%) | |
| lines%(i%, j%) = lines%(i%, j%) + 1 | |
| NEXT j% | |
| NEXT i% | |
| dt! = 1! / 60! | |
| dz! = .75! | |
| angle! = 0! | |
| done% = 0 | |
| DO WHILE done% = 0 | |
| IF INKEY$ = CHR$(27) THEN done% = 1 | |
| CLS | |
| PRINT "Turbo Basic - CGA (ESC to quit)" | |
| angle! = angle! + 3.1415! * dt! | |
| mcos! = COS(angle!) | |
| msin! = SIN(angle!) | |
| FOR i% = 1 TO 6 | |
| FOR j% = 1 TO linelen%(i%) | |
| l1% = lines%(i%, j%) | |
| j2% = j% + 1 | |
| IF j2% > linelen%(i%) THEN j2% = 1 | |
| l2% = lines%(i%, j2%) | |
| ax! = px!(l1%) : ay! = py!(l1%) : az! = pz!(l1%) | |
| bx! = px!(l2%) : by! = py!(l2%) : bz! = pz!(l2%) | |
| GOSUB RotTransProjA | |
| x1! = sx! : y1! = sy! | |
| GOSUB RotTransProjB | |
| x2! = sx! : y2! = sy! | |
| LINE (x1!, y1!)-(x2!, y2!), 3 | |
| NEXT j% | |
| NEXT i% | |
| ' Use DELAY instead of busy-wait | |
| DELAY 0.02 | |
| LOOP | |
| END | |
| ' --- Subroutines implemented as GOSUB blocks for max TB compatibility --- | |
| RotTransProjA: | |
| x! = ax! : y! = ay! : z! = az! | |
| GOSUB RotateXZ | |
| z! = z! + dz! | |
| x! = x! / z! | |
| y! = y! / z! | |
| sx! = ((x! + 1!) / 2!) * W% | |
| sy! = (1! - (y! + 1!) / 2!) * H% | |
| RETURN | |
| RotTransProjB: | |
| x! = bx! : y! = by! : z! = bz! | |
| GOSUB RotateXZ | |
| z! = z! + dz! | |
| x! = x! / z! | |
| y! = y! / z! | |
| sx! = ((x! + 1!) / 2!) * W% | |
| sy! = (1! - (y! + 1!) / 2!) * H% | |
| RETURN | |
| RotateXZ: | |
| tx! = x! | |
| tz! = z! | |
| x! = tx! * mcos! - tz! * msin! | |
| z! = tx! * msin! + tz! * mcos! | |
| RETURN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment