CLIP shows why graphics programs need clipping. Program #1 draws a growing many-petalled pattern by joining points on a curve; as soon as a line would run off the screen it stops with “B Integer out of range”. In Program #2, lines 100 and 230 are replaced by a clipping routine that checks each line segment against the 256 by 176 viewport and draws only the part that lies on the screen, so the pattern can grow past the edges. Changing n in line 10 gives other shapes.
It ran in Michael J. DiRienzo’s Mike’s Notebook column of November 1990, which notes that the program can be compiled with Novelsoft’s TIMACHINE. The download holds both programs on one tape: CLIP1 is Program #1 as printed and CLIP is Program #1 with Program #2 merged in.
Program Analysis
- Lines 10–90 compute end points
xe,yeon the curver=b*ABS (SIN (n*c)-COS (n*c))for growingb. - Lines 100–210 move the segment to coordinates relative to the screen centre (127.5, 87.5) and use
FN zto give −1, 0 or 1 for each end beyond, inside or past the edge in x and y. - If both ends are inside, line 220 draws the segment; if both are off the same side it is skipped; otherwise
FN xandFN ymove the outside ends to the edge and the test repeats. - Line 220 converts the absolute end point to the relative form DRAW needs with
PEEK 23677andPEEK 23678, the last plotted position.
Notable Techniques
SGN a*(ABS a>m)packs the outcode test into one function.- The clipping uses only BASIC and DEF FN, so it can be compiled.
Typed in from the Mike’s Notebook column on RMG Enterprises’ monthly RMG UPDATES disk for November 1990, where the program exists only as a listing in the column’s text. It was tokenized for tape and tested in ZEsarUX.
Source Code
10 LET n=6
20 FOR b=100 TO 590 STEP 70
30 FOR c=0 TO 810 STEP 19
40 LET r=b*ABS (SIN (n*c)-(COS (n*c)))
50 LET xe=128+r/6*COS c
60 LET ye=88+r/6*SIN c
70 IF c=0 THEN GO SUB 230
80 GO SUB 100: NEXT c: NEXT b
90 PLOT 0,0: DRAW 255,0: DRAW 0,175: DRAW -255,0: DRAW 0,-175: STOP
100 LET mx=127.5: LET my=87.5
110 LET x1=xs-mx: LET y1=ys-my
120 LET x2=xe-mx: LET y2=ye-my
130 GO SUB 300: GO SUB 330
140 IF NOT (s1 OR s2 OR t1 OR t2) THEN GO TO 220
150 IF NOT (s1*s2-1)*(t1*t2-1) THEN GO TO 230
160 IF s1 THEN LET y1=FN y(s1): LET x1=mx*s1: GO SUB 300
170 IF t1 THEN LET x1=FN x(t1): LET y1=my*t1
180 IF s2 THEN LET y2=FN y(s2): LET x2=mx*s2: GO SUB 330
190 IF t2 THEN LET x2=FN x(t2): LET y2=my*t2
200 GO SUB 300: GO SUB 330
210 IF (s1 OR t1 OR s2 OR t2) THEN GO TO 230
220 PLOT x1+mx,y1+my: DRAW x2+mx-PEEK 23677,y2+my-PEEK 23678
230 LET xs=xe: LET ys=ye
240 RETURN
300 LET s1=FN z(x1,mx)
310 LET t1=FN z(y1,my)
320 RETURN
330 LET s2=FN z(x2,mx)
340 LET t2=FN z(y2,my)
350 RETURN
500 DEF FN x(s)=x1+(my*s-y1)*(x2-x1)/(y2-y1)
510 DEF FN y(s)=y1+(mx*s-x1)*(y2-y1)/(x2-x1)
520 DEF FN z(a,m)=SGN a*(ABS a>m)Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

