Curves and surfaces on ZX SPECTRUM

6 minute read

Published:

Back in 2007, my dad shared with me his notebook about programming in BASIC language, which not only introduced me to programming but also made me fall in love with the BASIC dialect. Inside that notebook was a sheet of a page from Electronique Pratique magazine which displayed some BASIC code about curves and surfaces. I recently came across these sheets again while organizing my old documents.

The actual magazine is in fact available on Doctsf, and the BASIC dialect is Sinclair BASIC on the ZX SPECTRUM. So today I decided to run these codes. I used the Boriel BASIC compiler which allows me to write the code as “is” as if it were meant for the ZX Spectrum. Notably, it preserves the manual line numbering, which I have always found fascinating. I used Fuse - the Free Unix Spectrum Emulator - to visualize the output.

  • Cube
 5 REM cube
10 LET x = 25: LET y = 10
20 PLOT x,y: DRAW 75,0: DRAW 0,75: DRAW -75,0: DRAW 0,-75
30 LET x = x + 1: LET y = y + 2
40 IF x < 50 THEN GOTO 20
50 STOP

  • Astroid
 5 REM astroid 
10 FOR a = 0 TO 2*PI STEP PI/75
20 LET x = 5*COS a*COS a*COS a
30 LET y = 5*SIN a*SIN a*SIN a
40 PLOT 125+16*x,75+16*y
45 DRAW 25,10
50 NEXT a

  • 3d point
  5 REM representation d'un point dans l'espace
 10 PLOT 5,5: DRAW 250,0
 20 PLOT 5,5: DRAW 0,170
 30 PLOT 5,5: DRAW 250,170
 40 PLOT 35,5: DRAW -15,12,1
 50 PRINT AT 21,18;"X"
 60 PRINT AT 12,0;"Z" 
 70 PRINT AT 17,7;"Y" 
 80 PLOT 5,75:   DRAW 150,0: DRAW 0,-70
 90 PLOT 5,75:   DRAW 50,34: DRAW 150,0:  DRAW 0,-70
100 PLOT 155,5:  DRAW 50,34: DRAW -150,0: DRAW 0,70
110 PLOT 155,75: DRAW 50,34
120 PRINT AT 20,5;"a"
130 CIRCLE 204,108,3
140 PRINT AT 8,27;"M"
150 FOR Y = 5 TO 38 STEP 3
160 PLOT 204,Y
170 NEXT Y
180 PRINT AT 21,25;"P"
190 FOR X = 5 TO 54 STEP 3
200 PLOT X,108
210 NEXT X
220 PRINT AT 8,0;"Q"
230 PRINT AT 2,2;"Q=Z+(Y*SIN a)*k"
240 PRINT AT 6,17;"P=X+(Y*COS a)*k"
250 PAUSE 0

  • Surface 1
  10 FOR x = -1 TO 1 STEP 1/5
  20 FOR y = -1 TO 1 STEP 1/75
  40 GO SUB 1000
  70 NEXT y: NEXT x
  80 FOR y = -1 TO 1 STEP 1/5
  90 FOR x = -1 TO 1 STEP 1/75
 100 GO SUB 1000
 110 NEXT x: NEXT y
 200 STOP
1000 LET z = y/3*SIN x
2000 LET p = (x+y*.7)*50
3000 LET q = (z+y*.7)*50
4000 PLOT 125+p, 85-q
5000 RETURN

  • Surface 2
  10 FOR x = -1 TO 1 STEP 1/5
  20 FOR y = -1 TO 1 STEP 1/75
  40 GO SUB 1000
  70 NEXT y: NEXT x
  80 FOR y = -1 TO 1 STEP 1/5
  90 FOR x = -1 TO 1 STEP 1/75
 100 GO SUB 1000
 110 NEXT x: NEXT y
 200 STOP
1000 LET z = x*y/1.2
2000 LET p = (x+y*.7)*50
3000 LET q = (z+y*.7)*50
4000 PLOT 125+p, 85-q
5000 RETURN

  • Surface 3
  10 FOR x = -1 TO 1 STEP 1/5
  20 FOR y = -1 TO 1 STEP 1/75
  40 GO SUB 1000
  70 NEXT y: NEXT x
  80 FOR y = -1 TO 1 STEP 1/5
  90 FOR x = -1 TO 1 STEP 1/75
 100 GO SUB 1000
 110 NEXT x: NEXT y
 200 STOP
1000 LET z = x*x*x*x
2000 LET p = (x+y*.7)*50
3000 LET q = (z+y*.7)*50
4000 PLOT 125+p, 85-q
5000 RETURN

  • Surface 4
  10 FOR x = -1 TO 1 STEP 1/5
  20 FOR y = -1 TO 1 STEP 1/75
  40 GO SUB 1000
  70 NEXT y: NEXT x
  80 FOR y = -1 TO 1 STEP 1/5
  90 FOR x = -1 TO 1 STEP 1/75
 100 GO SUB 1000
 110 NEXT x: NEXT y
 200 STOP
1000 LET z = y*x*x
2000 LET p = (x+y*.7)*50
3000 LET q = (z+y*.7)*50
4000 PLOT 125+p, 85-q
5000 RETURN

  • Semi-sphere
   5 REM semi-sphere
  10 FOR a = 0 to PI STEP PI/10
  20 FOR b = 0 to PI STEP PI/100
  40 GO SUB 1000
  50 NEXT b: NEXT a 
  60 FOR b = 0 to PI STEP PI/10
  70 FOR a = 0 to PI STEP PI/100
  80 GO SUB 1000
  90 NEXT a: NEXT b
 200 STOP
1000 LET z = SIN a
1010 LET x = (COS a)*COS b
1020 LET y = (COS a)*SIN b
2000 LET p = (x+y*.6)*50
3000 LET q = (z+y*.6)*50
4000 PLOT 125+p, 85-q
5000 RETURN

  • World map
   5 REM world map
  10 FOR a = -PI to PI STEP PI/6
  20 FOR b = -PI to PI STEP PI/100
  40 GO SUB 1000
  50 NEXT b: NEXT a 
  60 FOR b = -PI to PI STEP PI/6
  70 FOR a = -PI to PI STEP PI/100
  80 GO SUB 1000
  90 NEXT a: NEXT b
 200 STOP
1000 LET z = SIN a
1010 LET x = (COS a)*COS b
1020 LET y = (COS a)*SIN b
2000 LET p = (x+y*.2)*70
3000 LET q = (z+y*.2)*70
4000 PLOT 125+p, 85-q
5000 RETURN

  • Sphere
   5 REM sphere
  10 FOR a = -PI to PI STEP PI/12
  20 FOR b = -PI to PI STEP PI/50
  40 GO SUB 1000
  50 NEXT b: NEXT a 
  60 FOR b = -PI to PI STEP PI/12
  70 FOR a = -PI to PI STEP PI/50
  80 GO SUB 1000
  90 NEXT a: NEXT b
 200 STOP
1000 LET z = SIN a
1010 LET x = (COS a)*COS b
1020 LET y = (COS a)*SIN b
2000 LET p = (x+y*.2)*70
3000 LET q = (z+y*.2)*70
4000 PLOT 125+p, 85-q
5000 RETURN

  • Tore
   5 REM tore
  10 FOR a = -PI to PI/3 STEP PI/6
  20 FOR b = -PI to 2*PI STEP PI/50
  40 GO SUB 1000
  50 NEXT b: NEXT a 
  60 FOR b = -PI to PI STEP PI/6
  70 FOR a = -PI to PI STEP PI/20
  80 GO SUB 1000
  90 NEXT a: NEXT b
 200 STOP
1000 LET z = SIN a
1010 LET x = (10*COS (a) +50)*COS b
1020 LET y = (10*COS (a) +50)*SIN b
2000 LET p = (x*.3 + y*.2)*5
3000 LET q = (z + y*.2)*5
4000 PLOT 135+p, 85-q
5000 RETURN