MODified Triangles

Developer(s): Peter McMullin
Date: 1986
Type: Program
Platform(s): ZX81, TS 1000, TS 2068
Tags: Graphics

Draws a large triangle made of smaller triangles, each turned eleven times so that every new triangle’s corners land a little way along the sides of the last, giving a spiralling geometric pattern. A one-line subroutine at line 6 does the work of the MOD operator, which Sinclair BASIC lacks. Peter McMullin adapted it from Paul W. Carlson’s “MODified Shapes for IBM” in COMPUTE!, May 1986.

It was printed for a ZX81 with the Oliger/TI video upgrade and JOBASIC or PIXL-ATR (line 810 draws with JOBASIC’s LPRINT) and for the TS2068 (line 815), with margin notes giving the TS2068 versions of lines 25 and 30; the reader deletes the line for the other machine. As printed, with both lines in place, it stops at line 810 with variable V not found. The next issue corrected line 730 to LET ARG=C, which changes the colour sequence.

Published in Sinc-Link May-June 1986 (ZX Resources).

Related Articles

Larken disk system; Eprom Services Programmer, MODified Shapes for T/S.
Update on ZX81 disk drives, Dungeons of Ymir, correction to program in prior article.

Image Gallery

Source Code

   1 REM MODified Triangles for Timex-Sinclair
   2 REM For ZX81: INITIALIZE JOBASIC OR PIXL-ATR VARIABLES
   3 GOTO 40
   5 REM MODULO SUBROUTINE
   6 LET RES=ARG-INT (ARG/MOD)*MOD
   7 RETURN
  10 REM IBM> TI/2068 PLOT SCALING
  15 LET XX1=(X1/1.25)+XSET
  20 LET XX2=(X2/1.25)+XSET     ●2068: USE
  25 LET YY1=191-(Y1/1.1)        YY1=175-(Y1/1.3)
  30 LET YY2=191-(Y2/1.1)        YY2=175-(Y1/1.3)
  35 RETURN
  39 REM TRIANGLE ROTATION
  40 DIM X(3)
  50 DIM Y(3)
  60 DIM Z(3)
  70 DIM T(3)
  80 LET XSET=1
 100 LET SU=.1
 110 LET RU=1-SU
 120 LET II=1
 130 LET C=1
 200 FOR J=0 TO 3               ●LOOP THRU J COLUMNS
 210 LET II=-II                  AND I ROWS
 220 LET JJ=1
 230 FOR I=0 TO 6
 240 LET JJ=-JJ
 250 IF I<J OR I>6-J THEN GOTO 1100
 300 IF J<2 OR I>2 THEN GOTO 320
 310 GOTO 400
 320 LET ARG=C                  ●ADVANCE COLOUR MOD 3
 330 LET MOD=3
 340 GOSUB 5
 350 LET C=RES+1
 400 IF J=3 THEN GOTO 420
 410 GOTO 500
 420 LET ARG=C                  ●ADVANCE COLOUR MOD 3
 430 GOSUB 5
 440 LET C=RES+1
 500 LET X(1)=0
 510 LET X(2)=39
 520 LET X(3)=78
 530 LET Y(1)=0
 540 LET Y(3)=0
 550 IF II=JJ THEN GOTO 580
 560 LET Y(2)=-48               ●CHANGE Y(2) VALUES TO PLOT
 570 GOTO 600                    SOME POLYGONS UPSIDE DOWN
 580 LET Y(2)=48
 600 FOR N=1 TO 11              ●LOOP THRU N ROTATIONS
 610 LET X1=3+X(3)+I*39
 620 LET Y1=175-Y(3)-J*48+II*JJ*24
 700 FOR M=1 TO 3               ●LOOP THRU M SIDES
 710 LET X2=3+X(M)+I*39
 720 LET Y2=175-Y(M)-J*48+II*JJ*24
 730 LET C=ARG
 740 GOSUB 5
 750 LET C=RES+1
 800 GOSUB 10
 802 REM SET INK COLOUR BY VARIABLE C
 803 REM C SEQUENCES MOD3 +1, IE 1,2,3,1,2,3,1...
 809 REM DRAW SIDE (JOBASIC):
 810 IF USR V THEN LPRINT D;XX1,YY1;XX2,YY2
 814 REM DRAW SIDE (2068):
 815 PLOT XX1,YY1:DRAW XX2-XX1,YY2-YY1
 820 LET X1=X2
 830 LET Y1=Y2
 840 LET ARG=M
 850 GOSUB 5
 860 LET NJ=RES+1
 900 LET Z(M)=RU*X(M)+SU*X(NJ)
 910 LET T(M)=RU*Y(M)+SU*Y(NJ)
 920 NEXT M
1000 FOR P=1 TO 3               ●MOVE RELATIVE COORDS
1010 LET X(P)=Z(P)               FROM "NEXT" ROTATION
1020 LET Y(P)=T(P)               TO "CURRENT" ROTATION
1030 NEXT P
1040 NEXT N
1100 NEXT I
1110 NEXT J
1200 IF INKEY$="" THEN GOTO 1200
1210 STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.