Level One routines are intended for incorporation into the user's own BASIC program. They offer the same kind of facilities as the Level Two routines but. with greater flexibility. In fact the Level One routines are the building blocks from which the Level Two routines are constructed.
Greater flexibility for the user than available from Level Two is provided because the user can vary the order in which routines are obeyed and it is possible to position a graph in any sector of the screen, and to vary the number of scale marks on an axis.
All Level One routines are accessed by PROC or FN calls as detailed later. All global variables used by the procedures are prefixed by E, 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 are listed later, the variables £0, £1, £2, and certain arrays which the user is sometimes required to set in order to pass data.
Procedure and function names are also prefixed with £, with the exceptions FNmin and FNmax. All line numbers used are in the range 10000 to 15999, but of course they may be renumbered with the RENUMBER command.
The default graphics parameters (see below) assume that the full screen is available for graphics, but the user may change this. The only interaction between Level One routines and the screen control facilities of the BBC microcomputer (using the VDU statement) is that the graphics foreground colour is changed and the graphics cursor is moved. All lettering is done by linking the text and graphics cursors but this link is always switched off before returning. The user is therefore free to use PLOT, VDU, etc. commands in the usual way to put titles etc on the display.
As explained in the introduction of this 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. There are two fundamental files of Level One routines, Ll-2D and Ll-3D. Normally you will require one or other of these files, but memory space permitting they can be loaded together if you wish. The other Level one routines are supplied individually on files, and so when they are wanted they should be loaded in addition to the fundamental files.
The BBC microcomputer has extensive and powerful graphics facilities built into it, but they require the user to address the screen in units which will not necessarily bear any relation to the units in which the user would perhaps like to work for a particular program. For example, if a bar chart of monthly sales was wanted, it might be nice to specify the bar heights in units of £s (or £1,000!) and the position horizontally of each bar in months. Level One routines are designed to enable the user to do just that.
For normal two dimensional plotting, the routines convert x-coordinates onto horizontal displacements on the screen, and y-coordinates onto vertical screen displacements. As the user may not always want to use the whole screen for a particular graph, a means is provided of specifying which region of the screen is to be used and what range of user coordinates is to be fitted onto the screen region. But even this information is not sufficient to enable axes to be drawn: the point in user coordinate space where the axes are to cross must also be specified. Usually this will be (0,0), but not always, as for example, one might wish to plot bar charts for the years 1945 to 1982 which does not include the year 0 AD.
The actual mapping used in two-dimensional plotting is therefore of the form:
X screen = £XCR + £XFA*(X-£SXO)
Y screen = £YCR + £YFA*(Y-£SYO]
where:
(X,Y) is the point in user coordinates to be plotted
(£SXO,£SYO) is the axes crossing point in user coordinates
(£XCR,£YCR) are the screen coordinates of the crossing point
(X screen, Y screen) are the screen coordinates of the point being plotted
£XFA, £YEA are scale factors
The screen coordinates are exactly as defined in the User Guide.
The information needed to set up this transformation is passed to the graphics routines by means of graphics parameters (see below). Similar considerations apply to 3-dimensional plotting: fuller details are given in the description of the axes procedures below.
If, during a run, the BASIC system were to report errors within the routines provided, this would usually be due to incorrect settings of the primary parameters (see next section). The user should check that PROCEINIT has been called to set these, or that the user's program has set all the parameters. Next, the actual values set by the user should be checked: note that the axis range parameters £XL, £XH, etc., must be set with £XL < £XH, and equality is not allowed (a range of zero width cannot be mapped onto a finite screen width) . Also £XI%, etc. , must be strictly positive, and zero values of XN% or £YN% could lead to division by zero.
Graphics parameters are just specially earmarked variables which are set to give the routines the data they need to work out the transformation from user or problem units to screen units. They include such things as the range of values for each axis (1945 to 1982 for example), the colour of each axis, how many intervals there are to be along each axis, etc.
There are actually two kinds of parameters: primary and secondary . Broadly speaking , the primary parameters are targets, that is values that the user would like to use, whereas the secondary parameters are the actual parameters used internally by the routines to define the scaling and transformations. The need for this distinction will become clearer as the structure of the routine is understood, but one example has already been mentioned, that is, the occasional need to shift the crossing point of the axes. The exact algorithm will be described later. One rule always holds: the secondary parameters are calculated from the primary parameters. However, it is not necessary to understand the secondary parameters in detail to use Level One routines. Another rule is that primary parameter values are never altered except by direct request of the user.
Each parameter has a default value, invoked by the function PROC£INIT (described below). Some parameters are not always required (e.g. all those referring to the Z-axis are not used in 2-D plotting), but all parameters are initialised by PROC£INIT, even if they are not going to be used.
It is important to note that the user is responsible for setting the primary parameters to sensible values. As most of the standard values will be satisfactory for most purposes, the most efficient way of doing this is to call PROC£INIT first, and then over-ride particular parameter values as required. But if the user over-rides any default values with nonsense values, errors will occur. One obvious error is, for example, to set £XL and £XH (low and high ends of the x-axis) to the same value which obviously prevents a scale factor being found.
Now follows a list of all the primary parameters and the values that they acquire as a result of calling PROC£INIT.
Parameter name | £XL | £YL | £ZL | £XH | £YH |
Default value | -10 | -10 | -10 | 10 | 10 |
Restrictions | High values must be strictly greater than low values. |
These parameters define the range of X, Y and Z values which must be at least spanned by the axes. The actual values used (i.e. the values of the corresponding secondary parameters] may be different but will always include the primary range . One reason for the difference might be that the interval size along an axis is not an exact fraction of the primary range (see below).
Parameter name | £XI% | £YI% | £ZI% |
Default value | 10 | 10 | 10 |
Restrictions | Values must be positive integers |
These parameters are used as a guide to the number of intervals that are to be marked off along each axis. The range is calculated from the primary parameters, and this is used to obtain a target interval size, for example:
target X-interval size = (£XH-£XL)/£XI%
The actual interval size used is the nearest of values of the form 1, 2 or 5 times a power of 10. This ensures that interval sizes are always sensible numbers. The axis range parameters (£XL, £XH etc) might not give multiples of the interval size, and thus the secondary parameters for the axis ranges may not be equal to the primary parameters.
Parameter name | £XO | £YO | £ZO |
Default value | 0 | 0 | 0 |
These parameters the point of intersection in the axes as drawn. The corresponding secondary parameters will only differ if this point does not map into the current screen sector (see below).
Parameter name | £XP% | £YP% | £ZP% |
Default value | 484040225 | 484040225 | 484040225 |
Each of these parameters contains 4 pieces of information. The first 3 digits (default 484) after having 500 subtracted (giving -16 by default) define a displacement in screen units which is used when labelling the axes to avoid the figures coming on top of the axis line. The next pair of digits (04) gives the maximum number of spaces that may be used for printing values alongside the axes. The next pair (02) is the 'pip mode'; value 2 makes the pips straddle the axis, 0 puts them on one side (above for X, to the right for Y and Z), I puts them on the other side. The final pair of digits defines the length of the pips as a percentage of interval size along one of the other axes (Y for X-axis, X for the Y and Z-axes).
These parameters allow the colours used when drawing the axes to be varied. If digit 7 (counting from the right, starting at 1) is zero, then when that axis is being drawn, having pips drawn, or labelled, the routines will not change the current graphics colour. But if digit 7 is 1, then each of the other pairs of digits defines the logical colour to be used for axes, pips, and labelling respectively. With default values, logical colour I will be used for axes, 2 for pips, and 3 for labelling. When using modes with less than 4 colours, £XC% is set to zero so that the graphics colours are never changed.
The operations of drawing axes, pips and labelling are done in the following order: X, Y, then Z--axes, X, Y, then Z pips, X, Y then Z labelling. Thus the default values give each axis the same colour scheme, because digit 7 is zero for the Y & Z axes.
Parameter name | £XN% | £YN% | £SN% |
Default value | 1 | 1 | 1 |
Restrictions | Values must be positive integers |
These parameters enable the screen to be divided into an arbitrary number of rectangular sectors and a particular graph drawn in just one. The diagram shows the effect of taking £XN% = 3, £YN% = 2, giving 3 intervals horizontally and 2 intervals vertically. Each sector is given a unique number (£SN%), numbered consecutively from left to right starting at £SN% = 1 for the lower left sector.
4 | 5 | 6 |
1 | 2 | 3 |
The screen area to be sectored is defined by further parameters - see below.
Parameter name | £TH | £PH |
Default value | 1.3 | -1.3 |
These parameters are only relevant for 3-D perspective plotting. They are the usual spherical polar angles in radians, and give the direction from which the graph is to be viewed. £TH is the angle between the line of sight and the Z-axis, and £PH is the angle between the x-axis and the plane through the line of sight and the Z-axis.
Parameter name | £HM% | £VM% | £CH% |
Default value | 64064 | 64064 | 32032 |
The default values actually depend on the mode in use. £CH% defines the width and height of characters in the mode selected, combined in the form 1000*width + height in screen units. £HM% and £VM% define how much of a margin is to be allowed inside the current screen sector when calculating scale factors, etc. £HM% is in the form 1000*(left margin) + (right margin), and £VM% similarly gives the top and bottom margin.
Parameter name | £XB% | £YB% | £XS% | £YS% |
Default value | 96 | 0 | 1184 | 1023 |
These parameters define the window within which plotting will be done. The window is a rectangle whose lower left corner is at (£XB%, £YB%] in screen coordinates and whose sides have length £XS%, £YS%, £XN%, £YN%, and £SN% determine how this window is to
Parameter name | £XM% |
Default value | none |
This parameter is set to the value of the argument M used in the call to PROC£INIT(M). It therefore records the mode that the user indicated for graphics. The routines never alter the graphics mode so this is not necessarily the actual mode at the time.
PROC£AXES(K) for 2-D plotting
PROC£AX3(K) for 3-D plotting
These procedures perform three separate actions, selected by K.
Action | |
0 | combines all the actions |
1 | sets the secondary parameters (sets up a transformation) |
1 | draws axes and mark them off with pips |
3 | labels the axes |
Although both routines conform to the above brief description, their actual effects are slightly different.
PROC£AXES only sets secondary parameters concerned with 2-D plotting. It first chooses a suitable interval size for marking off axes, in the manner described above (Section 4.5, see £XI%, etc.). If necessary, it then chooses a crossing point for the axes. This will differ from the primary parameter value only if that value lies outside the range to be spanned, and in that case a crossing point near the low end of the range is chosen. The actual end points of each axis are now chosen so that end points and axis crossing points all occur at integer multiples of the interval sizes (in user units). Next, the coordinates of the lower left hand corner of the chosen screen sector are calculated, together with the width and height of the sector. Scale factors are now calculated, and the horizontal and vertical factors are set to be equal if the initial calculation shows them to be within 30% of each other. The position of the axis crossing is now calculated in screen coordinates.
The axes are drawn and marked off. Finally, the axes are labelled. An attempt is made to label every axis marker, but if this would crowd the screen, only the end points are labelled. The labelling uses a printing format which may be scaled by powers of 10 if necessary. In that case the power of 10 used is displayed at the high end of the axis, using an E followed by the power of 10.
AX3 follows the same course for the X,Y,Z, axes up to the calculation of screen sector parameters. At this point axes ranges, interval size, and the screen sector have been chosen. To calculate the scaling factors a notional 3-1) box-shaped region is set up, having height equal to the sector height, width equal to the sector width, and depth equal to width.
Temporary scale factors are found which scale the user's x-range to width, y-range to depth, and z-range to height. The x and y factors are now equalised to the smaller of these two if the original values were within a ratio of 7/3 of each other. The x and z factor are next equalised if within 6/4 of each other.
The temporary factors must be further modified because under perspective projection, values of (X,Y,Z) lying within the notional box will not map into region PQRS, but into P'Q'R'S'. First the projection matrix elements are computed (formula below), then the extent of P'Q'R'S', using the temporary scale factors just found. A 'shrink factor' can now be found which reduces P'Q'R'S' to lie within the chosen screen sector. All the scale factors are then modified by this factor.
The projection is that obtained by projecting onto a plane orthogonal to the line of sight OE when the picture is viewed from infinity. THETA is the angle ZOE, and PHI the angle XOE' where OE' is the line of intersection of the plane through ZOE with the OXY plane.
If XF, YE, ZE are the scale factors, XC, YC the cm displacements from the axis crossing point on screen, and X,Y,Z the displacements from the user axis crossing:
XC | -sin (f) | cos(f) | 0 | XF*X | |
= | |||||
YC | -cos(q)cos(f) | -cos(q)sin(f) | sin(f) | YF*Y | |
ZF*Z |
The axis crossing point must now be positioned, which is done by finding the projection and user ranges the area of screen needed. The axis crossing point is then chosen to map this area centrally within the sector.
This algorithm is necessarily complicated and may not always achieve the effect desired by the user. The projection is defined entirely by secondary parameters which can of course be over-ridden by the user if desired (see below for list of these).
In order to make full use of the flexibility offered by Level One routines, the user may wish to over-ride some of the secondary parameters. For instance, the user may wish to be able to set the interval size between axis marks, or to set the scale factors explicitly.
The sequence of operations needed to achieve this will already be apparent from earlier sections. For instance, when using the 2-D routines, the user could break up the normal sequence of operations during a call to AXES as follows:
PROC£AXES(1) Set secondary parameters as usual
User code to over-ride any secondary parameters
PROCF£AXES(2) Draw axes
etc.
List of secondary parameters:
£SXL £SYL £SZL £SXH £SYH £SZH
define actual span of axes
£SKI £SYI £SZI
interval between pips on axes (user units)
£SXO £SYO £SZO £XCR% £YCR%
axes crossing point axes crossing point
(user units) (screen units)
Scale factors
£SXB% £SYB% £SXS% £SYS%
screen coords of base of current sector,
and length of its sides
£P11 £P12 £P21 £P22 £P23
elements of transformation matrix used for
3-D plotting
Some of these parameters are used in the transformation algorithms which map user coordinates into screen coordinates.
For 2-D plotting, the point (X,Y) is transformed as follows:
X screen = £XCR% + £XFA * (X - £SXO]
Y screen = £YCR% + £YEA * (Y - £SYO)
For 3-D plotting, the point (X,Y,Z) in user units is
transformed in two stages.
X' = £XFA * (X-£SXO)
Y' = £YEA * (Y-£SYO)
Z' = £ZFA * (Z-£SZO)
X screen = EXCR% + £P11*X' + £Pl2*Y'
Y screen = £YCR% + £P21 *X ' + £P22*Y' + £P23 *Z'
These procedures allow plotting to be done in the user's own coordinates.
PROCEINIT (M) PROC£AXES(K)
PROC£MOVE (X,Y) PROC£DRAW(X,Y) PROCEPLOT (K,X,Y)
FN£POINT(X,Y) FNmax(A,B) FNmin(A,B)
This set of routines is fundamental to all other 2-dimensional plotting routines. They allow the user to work in units which are appropriate to application rather than screen units as used by MOVE, DRAW, and PLOT.
Before any other procedure can be used, PROC£INIT(M) must be called with M set to the graphics mode that will be used when plotting. This initialises the primary graphics parameters (Section 4.6.1]. If any non-default values are required, these must be set at this point, after initialisation.
The next step is to call PROCF-AXES (K ) usually with K=0. This will 'set up a transformation', or in other words, will make it possible for the other routines to translate problem units into screen units. The call PROC£AXES(O) does this and also draws and labels the coordinate axes. It is possible to unbundle all these actions, indeed this is the purpose of the argument K.
K=1 sets up the transformation,
K=2 draws the axes, and
K=3 labels the axes.
Thus
10 PROC£AXES(0)
is equivalent to
20 PROC£AXES(1):PROC£AXES(2):PROC£AXES(3)
Once a transformation has been set, the procedures PROC£MOVE, PROC£DRAW, and PROC£PLOT may be used. These behave exactly as MOVE, DRAW and PLOT (as described in the BBC Microcomputer User Guide) except that X and Y are given in the user's own problem units.
Besides the routines named, this suite of routines also includes other routines used internally by the package. Listings are given in an appendix at the end of this manual. All internal procedure names start with E m accordance with the naming convention, with the exception of FNmin and FNmax. These functions return the minimum and maximum value respectively of the two arguments.
5 REM L1-2DX1
10 MODE1:PROC£INIT(1)
15 £XL=-.1:£XH=.1:£YL=-.1:£YH=.1
20 £XN%=2:£YN%=2
25 FOR S%= 1 TO £XN%*£YN%
30 £SN%=S%: PROC£AXES(0)
35 PROC£MOVE(0,0):GCOL 0,2
40 FOR th= 0 TO PI STEP 2*PI/100
50 r = .1*SIN(S%*th)
60 x = r *COS(th)
70 y = r *SIN(th)
80 PROC£DRAW(x,y)
90 NEXT:NEXT
100 END
200 REM -------------------------
These procedures allow plotting to be done in the user's own X,Y,Z coordinates, and produce a perspective view.
PROC£INIT(M) PROC£AX3(K)
PROC£MV3(X,Y,Z) PROC£DR3(X,Y,Z) PROC£PL3 (K,X,Y,Z)
FN£PT3 (X,Y,Z)
This is of routines are fundamental to all other is-dimensional plotting routines. They behave exactly like the 2-dimensional routines PROC£MOVE etc (see Ll-2D) except that the user must give three coordinates X,Y and Z.
Before any other procedure can be used, PROC£INIT(M) must be called with M set to the graphics mode that will be used when plotting. This initialises the primary graphics parameters (Section 4.6.1). If any non-default values are required, these must be set at this point, after initialisation. Note that some parameters which have no effect on '£-dimensional plotting now become useful, for example £TH and £PH which control the viewing angle used when drawing in perspective.
The next step is to call PROC£AX3(K), usually with K=0. PR0C£AX3(K) is the 3-dimensional equivalent of PROC£AXES; it sets up the perspective transformation. The argument K behaves just as in the 2-dimensional case.
Besides the routines named, this suite of routines also includes the same set of internal routines as for Ll-2D.
100 REM L1-3DX1
110 MODE1:PROC£INIT(1)
115 £XL=-1:£YL=-1:£ZL=-1
120 £XH=1:£YH=1:£ZH=1
130 PROC£AX3(0)
140 GCOL0,2:FOR I=0 TO 80: Z=2*I/80-1
150 x=COS(4*PI*Z): y=.3*SIN(4*PI*Z)
160 c=COS(Z*PI/2): s=SIN(Z*PI/2)
170 X=x*c-y*s: Y=x*s+y*c
180 IF I=0 THEN PROC£MV3(X,Y,Z) ELSE PROC£DR3(X,Y,Z)
190 NEXT:END
200 REM
PROC£CNTR(Z,IM%,JM%) - calls user-defined procedure PROC£PLOTCON(K,I,J)
This procedure assumes that the user has previously set up values in the array £W(I,J), which of course must also have been dimensioned. The routine will expect I to run between 0 and IM%, J between 0 and JM%. The set of points (I,J) with values in this range is called a 'mesh'. Usually, £W(I,J) is thought of as representing the values of points on a hill at distances X east, Y north from some fixed point of reference. The collection of points where the heights are known are called 'mesh points'. To draw a contour (in our example the curve along which all points of the hill are at constant height), the routine has to find all the places where the heights are the wanted height, which will have been specified in the first argument Z of the call to PROC£CNTR. These places will not all lie exactly at the mesh points; if you imagine the mesh points all joined up into a set of squares, then PR0C£CNTR actually finds the places where the contour crosses any side.
PROC£CNTR does not actually join all these points up itself. Instead, it calls another routine which the user must have defined in his own part of the program. This must be called PROCF-PLOTCON, and must expect arguments K,I,J, PROC£CNTR will call PROCF-PLOTCON every time it finds a place where a contour crosses the side of a mesh square, and it will set K to 4 if a MOVE is required, and to 5 if a DRAW is required. I and J will be set to the crossing place using mesh coordinates; it is up to the user to decide whether to convert these to his own system before calling a plotting routine. Note that I and J as set on this call need not be whole numbers, and that K follows the control variable convention as used in PLOT (in the BBC Microcomputer User Guide]. It is also important to note that care must be taken wit thin PROCF-PLOTCON if global variables are to be used; these must not have the same names as any of PROC£CNTR's local variables, because the interpreter will not restore the global values until it finds an ENDPROC statement to take it out of PROCECNTR. Local variables used by PROCE'CNTR are: D, F%, I%, IM%, J%, JM%, K%, X, Y, Z, ZO, ZI. It is of course perfectly alright to use local variables with these names. It may also be useful to note that Z, IM% and JM% take the values of the corresponding arguments throughout the routine.
10 REM L1-CNX1
30 MODE5:PROC£INIT(5)
40 £XL=-1:£XH=1:£YL=-1:£YH=1
50 PROC£AXES(0)
60 N=10:NH=5:N2=NH^2:DIM £W(10,10)
70 FOR I=0 TO N: FOR J=0 TO N
80 £W(I,J)=(I-NH)*(J-NH)/N2:NEXT:NEXT
90 FOR Z=-1 TO 1 STEP .09999
100 IF Z<0 THEN GCOL 0,1 ELSE GCOL 0,2
110 IF ABS(Z)>.01 THEN PROC£CNTR(Z,N,N)
120 NEXT
130 END
140 REM ------ Plotting procedure ---
150 DEF PROC£PLOTCON(K%,I,J): LOCAL X,Y
160 X=(I-NH)/NH:Y=(J-NH)/NH
170 PROC£PLOT(K%,X,Y)
180 ENDPROC
199 REM-------------------------------
10 REM L1-CNX2
30 MODE5:PROC£INIT(5)
40 £XL=-1:£XH=1:£YL=-1:£YH=1
50 £ZL=-1:£ZH=1:PROC£AX3(0)
60 N=10:NH=5:N2=NH^2:DIM £W(10,10)
70 FOR I=0 TO N:FOR J=0 TO N
80 £W(I,J)=(I-NH)*(J-NH)/N2:NEXT:NEXT
90 FOR Z=-1 TO 1 STEP .09999
100 IF Z<0 THEN GCOL 0,1 ELSE GCOL 0,2
110 IF ABS(Z)>.01 THEN PROC£CNTR(Z,N,N)
120 NEXT
130 END
140 REM ------ Plotting procedure ---
150 DEF PROC£PLOTCON(K%,I,J): LOCAL X,Y
160 X=(I-NH)/NH:Y=(J-NH)/NH
170 PROC£PL3(K%,X,Y,Z)
180 ENDPROC
199 REM ------------------------------
This procedure assumes that the user has previously called PROCEINIT or otherwise set £SXB, £SYB, £SYS, and draws a box around the region so defined in the current graphics colour.
This procedure assumes that there has previously been a call to PROCEINIT and PROCE-AXES so that a 'z-dimensional transformation has been set up. Using the current graphics colour , it draws a bar, positioned according to K and X, base of bar at height YO, top of bar at Y, and of width W.
If K=0, then the left side of the bar is at X, and if K=l, then the bar is centred at X.
It is allowed for Y to be less than YO, so that 'downward' bars may be drawn.
210 REM L1-BAX1
220 MODE1:PROC£INIT(1)
230 £XL=0:£YL=0:£XH=10:£YH=10
240 £XC%=1010303
250 PROC£AXES(0)
260 REM generates 30 random no.s
270 REM and count frequency.
280 DIM Y(10)
290 FOR I%=1 TO 30
300 J%=10*RND(1): Y(J%)=Y(J%)+1: NEXT
310 GCOL 0,2
320 FOR I%=0 TO 9:PROC£BAR(0,I%+.1,0,Y(I%),.7):NEXT
325 PROC£MOVE(1,9):VDU5:GCOL 0,1
328 PRINT "Random number histogram"
330 VDU4:END
210 REM L1-BAX2
220 MODE1:PROC£INIT(1)
230 £XL=0:£YL=0:£XH=10:£YH=14
240 £VM%=128128:£HM%=128128:£XC%=1010303
250 PROC£AXES(0)
260 REM twice generate 30 random no.s
270 REM and count frequency.
280 DIM Y(10),Z(10)
290 FOR I%=1 TO 30
295 J%=10*RND(1): Z(J%)=Z(J%)+1
300 J%=10*RND(1): Y(J%)=Y(J%)+1: NEXT
320 FOR I%=0 TO 9
322 GCOL 0,2:PROC£BAR(0,I%+.1,0,Y(I%),.7)
324 GCOL
0,1:PROC£BAR(0,I%+.1,Y(I%),Z(I%)+Y(I%),.7):NEXT
325 PROC£MOVE(1,£SYH-1):VDU5:GCOL 0,1
328 PRINT "Random number histogram"
330 PROC£MOVE(1,£SYH-1):VDU10:VDU10
332 PRINT"Level One, example 2"
340 VDU4:VDU30:END
PROC£SEC(M,X,Y,R,A,B)
This procedure draws and fills in a sector of a circle, whose centre is at X,Y, and whose radius is R, and which starts at angle A and covers an angle B. All angles are measured in revolutions (so I is a full circle, .5 is half a circle, etc.), and are measured anti clockwise from the right hand horizontal direction.
The units expected for X, Y and R depend on the control variable M. This should be thought of as having two digits ab. If a=0, then X and Y are expected in screen coordinates, and if a=1, then they must be in user coordinates and a transformation must have been set up (by previous use of PROC£AXES for example). Similarly, b=0 means that R is in screen units, and b=1 means user units.
On leaving the procedure, the graphics cursor is left at a point inside the sector ready for text or labelling.
400 REM L1-SEX1
420 MODE1:PROC£INIT(1):a%=@%:@%=&1000202
430 PROC£AXES(1)
440 REM generate 200 random no.s
450 REM and count frequency.
460 DIM Y(10)
470 FOR I%=1 TO 200
480 J%=10*RND(1):Y(J%)=Y(J%)+1:NEXT
490 A=0:FOR I%=0 TO 9:B=A+Y(I%)/200
500 IF I%MOD2=0 THEN GCOL 0,1 ELSE GCOL 0,2
505 REM ---- draw the pie sector ---
510 PROC£SEC(11,0,0,10,A,B)
512 REM
515 VDU5:VDU8:GCOL 0,0:PRINT Y(I%):VDU4
520 A=B:NEXT:GCOL 0,3
525 PRINT TAB(10,30);"Example of pie chart"
530 VDU30:@%=a%:END