THE 'DRAW' ALGORITHM
The following BASIC program illustrates the essential parts of the DRAW operation
when being used to produce a straight line. The program in its present form only allows
for lines where X > Y.
10 REM DRAW 255,175 PROGRAM
20 REM SET ORIGIN
30 LET PLOTx=0: LET PLOTy=0
40 REM SET LIMITS
50 LET X=255: LET Y=175
60 REM SET INCREMENT,i
70 LET i=X/2
80 REM ENTER LOOP
90 FOR B=X TO 1 STEP -1
100 LET A=Y+i
110 IF X> A THEN GO TO 160
120 REM UP A PIXEL ON THIS PASS
130 LET A=A-X
140 LET PLOTy=PLOTy+1
150 REM RESET INCREMENT,i
160 LET i=A
170 REM ALWAYS ALONG ONE PIXEL
180 LET PLOTx=PLOTx+1
190 REM NOW MAKE A PLOT
200 PLOT PLOTx,PLOTy
210 NEXT B
A complete algorithm is to found in the following program, as a subroutine that will
'DRAW A LINE' from the last position to X,Y.
THE 'CIRCLE' ALGORITHM
The following BASIC program illustrates how the CIRCLE command produces its
circles.
Initially the number of arcs required is calculated. Then a set of parameters is pre-
pared in the 'memory area' and the 'calculator stack'.
The arcs are then drawn by repeated calls to the line drawing subroutine that on each
call draws a single line from the 'last position' to the position 'X,Y'.
Note: In the ROM program there is a final 'closing' line but this feature has not been
included here.
10 REM A CIRCLE PROGRAM
20 LET X=127: LET Y=87: LET Z=87
30 REM How many arcs?
40 LET Arcs=4*INT (INT (ABS (PI*SQR Z)+0.5)/4)+4
50 REM Set up memory area; M0-M5
60 LET M0=X+Z
70 LET M1=0
80 LET M2=2*Z*SIN (PI/Arcs)
90 LET M3=(SIN (PI/Arcs)) ^ 2
100 LET M4=SIN (2*PI/Arcs)
110 LET M5=2*PI
120 REM Set up stack; Sa-Sd
130 LET Sa=X+Z
140 LET Sb=Y-Z*SIN (PI/Arcs)
15) LET Sc=Sa
160 LET Sd-Sb
170 REM Initialise COORDS
180 POKE 23677,Sa: POKE 23678,Sb
190 LET M0=Sd
200 REM 'DRAW THE ARCS'
210 LET M0=M0+M2
220 LET Sc=Sc+M1
230 LET X=Sc-PEEK 23677
240 LET Y=M0-PEEK 23678