contour_it

Developer(s): Al Boehm
Date: 1988
Type: Diskette
Platform(s): QL
Tags: Graphics

Draws banded colour contours of a mathematical function on the Sinclair QL, as used for mean cloud contours: a 7 by 7 grid of values from a sine function is shaded line by line across the screen, each whole-number band in its own INK colour. The procedure contour can be called with any array; line 135 suggests random values instead.

The author, at the Air Force Geophysics Laboratory, dated it 20 December 1987. The editor recommends it as a demonstration of SuperBASIC parameter passing and SCALE coordinates; the REMarks advise MODE 8.

Published in the BCS Sinclair-Timex User Group Newsletter January 1988 (Clouds on a QL).

Source Code

1 REMark test of contour using a math function.
2 REMark   20 Dec 1987
3 REMark   by A. Boehm
100 nnx=6:nny=6:DIM z(nnx,nny)
110  FOR i=0 TO nnx
120  FOR j=0 TO nny
130  z(i,j)=10*SIN(i/10*2*PI+ j/6*2*PI)+ i*j/2
135 REMark also try z(i,j)=10*RND
140  NEXT j
150  NEXT i
160 contour z,nnx,nny
170 STOP
180 DEFine PROC contour(z,nx,ny)
185 REMark Prints banded contours of the values in z.  Use MODE 8 for best results.  A contour interval of 1 is assumed.  For other contour intervals, let z(i,j)=z(i,j)/contour_interval before calling contour.
190 across=511:down=255:left=0: top=0
200 WINDOW across,down,left,top
210 PAPER 0:CLS
220 SCALE ny,0,0
225 dx=across*.628/down*ny/nx
230 yline=ny/down
240 FOR j=0 TO ny-1
250 x1=0:x2=dx
260 FOR i=0 TO nx-1
270 con_a_block z(i,j),z(i+1,j), z(i,j+1),z(i+1,j+1),j
280 x1=x2:x2=x2+dx
290 NEXT i
300 NEXT j
310 RETurn
320 END DEFine contour
330 DEFine PROCedure con_a_block (a,b,c,d,ystart)
340 LOCal dz,fx,x,i,j
350 aa=a:bb=b
360 da=yline*(c-a)
370 db=yline*(d-b)
380 FOR y=ystart TO ystart+1 STEP yline
390 POINT x1,y
400 i=INT(aa):j=INT(bb)
410 INK i MOD 8
420 IF i=j THEN LINE TO x2,y: GO TO 530
430 dz=ABS(bb-aa):n=ABS(j-i)
440 fx=aa-i:IF i<j THEN fx=1-fx
450 IF n=1 THEN LINE_R TO fx*dx/dz,0: GO TO 520
460 fy=b-j:IF j>i THEN up=1: ELSE up=-1:fy=1-fy
470 x=dx/dz
480 LINE_R TO fx*x,0
490 FOR k=i+up TO j-up STEP up
500 INK k MOD 8:LINE_R TO x,0
510 END FOR k
520 INK j MOD 8:LINE TO x2,y
530 aa=aa+da:bb=bb+db
540 END FOR y
550 END DEFine con_a_block

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