These routines are intended for incorporation into the user's own BASIC program. They are 'minimum fuss' routines: in your part of the program you will have perhaps to dimension certain arrays and set values in them, and then call just one procedure to get graphical displays. In exchange for ease of use, you have to accept certain choices that will be made automatically by the routines. If these need to be changed, you will need to use Level One procedures.
All Level Two routines are accessed by FROG calls as detailed later. All global variables used by the procedures are prefixed with £, a convention which should prevent any clash of names with the user's own program. In fact the only such global variables are the graphics parameters which will be listed later, the variables £0, £1, £2, and certain arrays which the user is sometimes required to set in order to pass data. Obviously you should not use these variables in your part of the program except as specified.
Procedure and function names are also prefixed with E, with the exceptions of FNmin and FNmax. All line numbers used are in the range 10000 to 17999, but of course they may be renumbered with the RENUMBER command.
The routines assume that the full screen is available for graphics. Only the graphics cursor is moved, and only the foreground graphics colour is changed. VDU and other cursor control commands may be freely used in the user's program.
As explained in the introduction of the manual, the routines are supplied on cassette in a form that can be read using the *EXEC command. This is done so that the routines can be added to-an existing program. In addition to the Level Two tile that you are going to use, one of the fundamental Level One files Ll-2D or Ll-3D must also be loaded (using *EXEC). The detailed specifications tell you which.
If, during a run, the BASIC system were to report errors within the routines provided, this would usually be due to a fail are by the routines to calculate a suitable scale factor for the data you have provided. For example, in L2-XY, suppose you set all the values £Y(I) to the same value, then the routines will give up because the range of Y-values is zero.
PROC£HIS(M,N,W) - Requires Ll-2D
If you have a program which has calculated some data, or read it in from a data file, or whatever, such as monthly sales figures, then you can use this procedure to create a bar chart (also known as a histogram).
Your program must first store the data in two arrays £X(I) and £Y(I), which you must previously dimension according to what you need. £Y(I) will be the height of bar number I; the height may be in any units you like, and I must be in the range O to N. Note that this means that N+l bars will be drawn. £X(I) will specify the horizontal position of the bar, for example month in the range I to 12. You can store the data in any order, it doesn't have to be in numerical order, but each £X(I) and £Y(I) must correspond.
To draw the chart, call PROC£HIS (M,N,W), where M is the mode you want to use, N is the maximum for the index I ( = one less than number of bars), and W is the width of each bar in your own units.
You may call the routine again with M set greater than 10 and other values set as above to a new set of data. The routine will repeat its actions except that it will assume axes are already set up.
10 REM L2-HIX1
30 REM
40 REM dimension arrays for data
50 DIM £X(10),£Y(10)
60 REM now ask for data
70 INPUT "How many bars",N
75 REM N-1 will be max subscript
80 FOR I=0 TO N-1
90 PRINT "Bar ";I+1;
95 INPUT " height",H
100 £X(I)=I+.1:£Y(I)=H
110 NEXT
120 REM
130 REM ----- now call PROC£HIS ----
140 REM with bar width .7
150 MODE 5: PROC£HIS(5,N,.7)
160 END
400 REM L2-HIX2
420 REM
430 REM generate 30 random no.s
440 REM and count frequency.
450 DIM £X(10),£Y(10)
460 FOR I%= 1 TO 50
470 J%=10*RND(1): £Y(J%)=£Y(J%)+1:NEXT
480 REM generate vector of X-values
490 FOR I%=0 TO 9:£X(I%)=I%:NEXT
500 REM
510 REM ----- now call PROC£HIS ----
520 MODE1:PROC£HIS(1,9,.7)
530 END
540 REM ----------------------------
PROC£PIE (M,N) - Requires Ll-2D
Pie charts are useful if you want to show an analysis of a total figure, for example to show the contribution of various departments to the earnings of the parent organisation as a whole. This procedure would be useful if you had a program that could calculate these figures and you then wanted to display them.
Your program must first store the data in the array £Y(I), which you must dimension previously according to what you need. £Y(I) will be the size of sector number I as a percentage of a full circle. I must be in the range 0 to N. Note that this means that N+l sectors will be drawn. The data must be stored in the order in which the sectors are to be drawn. The first sector will start from the 3 o'clock position and drawing is anti-clockwise from there. There is no need for the £Y(I) values to add up to 100%; if that is what you want you must ensure that your part of the program makes them do so.
To draw the chart, call PROC£PIE(M,N) where M is the mode you want to use, N is the maximum for the index I ( = one less than number of sectors j.
10 REM L2-PIX1
30 REM
40 REM dimension array for data
50 DIM £Y(20)
60 REM now ask for data
70 INPUT "How many sectors ",N
80 REM N-1 will be max subscript
90 PRINT "Input sector sizes in %"
100 FOR I=0 TO N-1
110 PRINT "Sector ";I+1;
120 INPUT " size ",£Y(I)
130 NEXT
140 REM
150 REM ----- now call PROC£PIE ---
160 MODE5:PROC£PIE(5,N-1)
170 END
PROC£XY(M,N) - Requires L1-2D
This procedure produces the most familiar form of graph, as used for example to show stockmarket indices, money supply, daily temperatures, etc. In most of these examples, time (e.g. days) runs left to right across the page, and usually a line (an 'axis') is drawn with intervals marked off along it. The quantity being graphed (e.g. temperature) is measured in an up and down direction and usually an axis is drawn for this too, marked off, for example, in centigrade. These axes are of ten call ed the horizontal, or X-axis, and vertical, or Y-axis. Any position on the graph may now be specified by giving two coordinates (X,Y). Successive points are joined to produce the graph. Graphs are also useful for representing mathematical functions, for example y=sin(x). By working out y for sufficiently closely spaced values of x, a smooth curve will appear to be drawn.
Assuming that your program can calculate the coordinates (X,Y) for each point to be joined up on the graph, all that the routine requires is that you store these values successively in the arrays £X(I), £Y(I) where I take values from 0 to N inclusive. Thus there will be N+l points on the graph and N lines between them. The arrays must have been dimensioned in your part of the program.
To draw the graph, call PR0C£XY(M,N), where M is the mode you want to use, N is the maximum for the index I ( = one less than number of points, = number of lines joining them).
If having called PROC£XY as above you want to draw more graphs on the same axes, you can do this by storing the new data in £X(I) and £Y(I) and then calling PROC£XY(M,N) again but with M greater than 10.
10 REM L2-XYX1
30 REM
40 REM Input coordinates of some
50 REM points and join them up.
60 REM
70 INPUT "How many points to join ",N
80 REM Dimension arrays for coords.
90 DIM £X(10),£Y(10)
100 FOR I=0 TO N-1 : REM N points
110 PRINT "Point ";I+1;
120 INPUT " X,Y ",£X(I),£Y(I)
130 NEXT
140 REM
150 REM ---- now call L2-XY to draw--
160 MODE5:PROC£XY(5,N-1)
170 REM ---- that's all ----
180 END
500 REM L2-XYX2
520 REM
530 REM --- simple x,y plot ---
540 REM first DIM £X,£Y & set values
550 DIM £X(40),£Y(40)
560 N%=40
570 FOR I%=0 TO N%: th=I%*PI/N%
580 r = SIN(5*th)
590 £X(I%)= r *COS(th)
600 £Y(I%)= r *SIN(th)
610 NEXT
620 REM --- now call PROC£XY ---
630 MODE5:PROC£XY(5,N%)
640 END
650 REM --- that's all ---
PR0C£XYZ(M,N) - Requires Ll-3D
The complete 2-dimensional graph plotter L2-XY used values that the user had stored in £X(I), £Y(I) to craw a 'flat' graph. This procedure extends the idea to 3 dimensions. As the computer screen is only 2-dimensional, the best that can be done is to produce a perspective view of the graph. J
Your program should dimension the arrays £X(I), £Y(I) and £Z(I), and store in them the coordinates of the points to be joined up into the graph. As for 'z-dimensional graphs, mathematical curves can be made to look quite smooth by taking the points close enough together. Then call PROC£XYZ(M,N), where M is the mode to be used, N is the maximum subscript of the arrays.
If having called PROC£XYZ as above you want to draw more graphs on the same axes, you can do this by storing the new data in £X(I), £Y(I) and £Z(I), and then calling PROCF-XY (M, N ) again but with M greater than 10.
10 REM L2-XYZ1
40 REM
50 REM dimension arrays
60 DIM £X(50),£Y(50),£Z(50)
70 REM
80 REM --- ask for data ---
90 INPUT "No. of points ",N
100 FOR I=0 TO N-1
110 PRINT"Point ";I;
120 INPUT " X,Y,Z= ",£X(I),£Y(I),£Z(I)
130 NEXT
140 REM
150 REM --- now call L2-XYZ ---
160 MODE1:PROC£XYZ(1,N-1)
170 END
200 REM L2-XYZ2
240 REM
250 REM dimension arrays
260 DIM £X(60),£Y(60),£Z(60)
270 REM
280 REM calculate data
290 N=60: dt=2*PI/N
300 FOR I=0 TO N
310 t=I*dt: r=4+COS(8*t)
320 £X(I)=r*COS(t)
330 £Y(I)=r*SIN(t)
340 £Z(I)=SIN(8*t)
350 NEXT
360 REM
370 REM --- now call L2-XYZ ---
380 MODE1:PROC£XYZ(1,N)
390 t=INKEY(300): MODE1
400 REM repeat, forcing axes ranges
410 £ZL=-5:£ZH=5:PROC£AX3(0)
420 GCOL0,2:PROC£XYZ(11,N)
430 END
PROC£CN2D(M,IM,JM,N) - Requires Ll-2D
Contour maps are a useful way of representing functions of two variables. On a graph with X and Y-axes for example one might have a function of X and Y which represented the height of a hill; that is, for each point (X,Y) the height could be calculated from some function £(X,Y), Contours are the curves along which the function value (height) is constant, just as on Ordnance Survey maps.
To draw a contour map, you must first work out the function at a number of regularly spaced points. Suppose for example that you wanted to map the region X between 0 and 100, Y between -10 and 10. You must decide how to space out the points; one possibility is to take all the points with X-coordinates 0, 10, 20, 30, ..... 100, and Y--coordinates -10, -8, -6, ... 0, 2, 4, ... 10. Every X-coordinate could pair up with any Y-coordinate, so you get 11 x 11 = 121 points altogether. These are called 'mesh points' or 'grid points'. The values of your function must be stored in a 2-dimensional array £W(I,J) where I counts the points along the X-axis, J counts along the Y-axis, numbering from O upwards. Let IM be the maximum value taken by I, and JM the maximum value for J. In our example IM=JM=10, but they might be different in general. Your program must dimension £W , of course.
To draw the map, call PROC£CN2D(M,IM,JM,N), where M is the mode you want to use, IM and JM are as defined above, and N is the number of contours that you want drawn. These will be at evenly spaced heights throughout the range found in the values in £W(I,J).
You may call the routine again with M set greater than 10 and other values set as above to a new set of data. The routine will repeat its actions except that it will assume axes are already set up.
10 REM L2-C2X1
30 DIM £W(10,10)
40 FOR I%=0 TO 10:FOR J%=0 TO 10
50 X=(I%-5):Y=(J%-5)
60 £W(I%,J%)=X^2+Y^2/2
70 NEXT:NEXT
80 REM now call PLOT£CN2D
90 MODE5:PROC£CN2D(5,10,10,10)
100 END
PROC£CN3D(M,IM,JM,N) - Requires Ll-3D
This procedure works in the same way as L2-CN2D except that the contours are drawn in perspective view according to height.
The array £W(I,J) must be dimensioned and set exactly as for L2-CN2D, then the call PR0C£CN3D(M,IM,JM,N) will draw the contours.
10 REM L2-C3X1
30 DIM £W(10,10)
40 FOR I%=0 TO 10:FOR J%=0 TO 10
50 X=(I%-5):Y=(J%-5)
60 £W(I%,J%)=X^2+Y^2/2
70 NEXT:NEXT
80 REM now call PROC£CN3D
90 MODE5:PROC£CN3D(5,10,10,10)
100 END
200 REM L2-C3X2
230 DIM £W(12,8)
240 REM
250 REM set w = cos(x).sin(y)
260 FOR J=0 TO 8: B=SIN(J*PI/8)
270 FOR I=0 TO 12
280 £W(I,J)=B*COS(I*PI/6)
290 NEXT
300 NEXT
310 REM
320 REM now call PLOT£CN3D (12 contrs)
330 MODE1:PROC£CN3D(1,12,8,12)
340 END
PROC£SURF(M,IM,JM) - Requires Ll-3D
The procedure L2-CN2D provides one way of representing functions of two variables by drawing 'flat' contours, and L2-CN3D enables those contours to be drawn in perspective. This procedure gives an additional method: imagine that all the points on a hill at the 'grid points' (see L2-CN2D) were joined to their neighbours by wires. If the hill were then taken away, you would be able to look at the wire frame left behind. L2-SURF draws this wire frame in perspective, which gives quite a good idea of the underlying surface.
To use the routine, set values in £W(I,J) just as for L2-CN2D, and then call PROCE-SURF (M,IM,JM). M is the mode to be used, IM, JM are the maximum values of I,J.
You may call the routine again with M set greater than 10 and other values set as above to a new set of data. The routine will repeat its actions except that it will assume axes are already set up.
10 REM L2-SUX1
40 REM
50 REM first dimension £W(I,J)
60 DIM £W(10,10)
70 REM
80 REM now calculate values
90 FOR I%=0 TO 10:FOR J%=0 TO 10
100 X=(I%-5):Y=(J%-5)
110 £W(I%,J%)=X^2+Y^2/2
120 NEXT:NEXT
130 REM
140 REM now call PROC£SURF
150 MODE1:PROC£SURF(1,10,10)
160 END
200 REM L2-SUX2
230 REM
240 REM first dimension £W(I,J)
250 DIM £W(12,8)
260 REM
270 REM set w = cos(x).sin(y)
280 FOR J=0 TO 8: B=SIN(J*PI/8)
290 FOR I=0 TO 12
300 £W(I,J)=B*COS(I*PI/6)
310 NEXT
320 NEXT
330 REM
340 REM now call PROC£SURF
350 MODE1:PROC£SURF(1,12,8)
360 END
PROC£STEREO(M,N) - Requires Ll-3D
This procedure is like L2-XYZ but instead of a single graph it gives a pair in different colours viewed from slightly different angles. Because good resolution is needed, MODE 1 is recommended.
To use, set £X(I), £Y(I) and £Z(I) as for L2-XYZ, and then call PRCC£STEREO(M,N) where M is the nude to use and N is the maximum value of 1.
If called with M greater than 10, the axis ranges and other relevant parameters are assumed to be already set up, either by a previous call to PROC£STEREO by the technique described on page 46.
200 REM L2-STX1
240 REM
250 REM dimension arrays
260 DIM £X(60),£Y(60),£Z(60)
270 REM
280 REM calculate data
290 N=60: dt=2*PI/N
300 FOR I=0 TO N
310 t=I*dt: r=4+COS(8*t)
320 £X(I)=r*COS(t)
330 £Y(I)=r*SIN(t)
340 £Z(I)=SIN(8*t)
350 NEXT
360 REM
370 REM --- now call L2-STEREO ---
380 MODE1:PROC£STEREO(1,N)
390 t=INKEY(300): MODE1
400 REM repeat, forcing axes ranges
410 £ZL=-5:£ZH=5
420 PROC£STEREO(11,N)
430 END
An alternative technique to the two-colour pair is to use two views side-by-side, one a mirror image of the other. Shown below are suitable modifications to the example and to L2-STER itself. To view, hold a mirror between the two views so the reflective face is vertical, is at right angles to the screen, and faces right. Position your head so that the mirror is mid-way between your eyes. Look at the left view; your right eye should see the reflection of the right-hand view on top of the left-hand view. Adjust your position until the images coincide.
Modifications
380 MODE 1: PROC£INIT(1)
390 £XL=-6: £XH=6:£YL=-6:£YH=6
400 £ZL=-5: £ZH=5
410 PROC£STEREO(11,N)
420 END
17290 DEFPROC£STEREO(I%,N%):LOCAL S
17420 £XB%=0:£YB%=200: £XS%=700:£YS%=700
17430 £HM%=0: £VM%=0: £XC%=0: £PH=-1.3
17440 S=1:GOSUB 17470
17450 £XB%=600: £PH=-1.29:S=-1
17460 GOSUB 17470:ENDPROC
17470 GCOL 0,1:PROC£AX3(1):£P11=S*£P11
17475 £P12=S*£P12:PROC£AX3(2):GCOL 0,2
PROC£STSURF(M,IM,JM) - Requires Ll-3D
This procedure is like L2-SURF but instead of a single graph it gives a pair in different colours viewed from slightly different angles. Mode 1 is recommended, and if M is greater than 10 the same remarks apply as for L2-STER (page 30]. To use, set £W(I,J) as in L2-S0RF, and then call PRCEESTSURF (M,IM,JM) where M is mode to use, IM and JM are maximum values I and J.
Side-by-side views can obtained with modifications similar to those suggested for L2-SFER (see gages 30-31).
200 REM L2-SSX1
230 REM
240 REM first dimension £W(I,J)
250 DIM £W(12,8)
260 REM
270 REM set w = cos(x).sin(y)
280 FOR J=0 TO 8: B=SIN(J*PI/8)
290 FOR I=0 TO 12
300 £W(I,J)=B*COS(I*PI/6)
310 NEXT
320 NEXT
330 REM
340 REM now call PROC£STSURF
350 MODE1:PROC£STSURF(1,12,8)
360 END