The following article was printed in November 1988 of the magazine „8000 PLUS".
GSX routines in BASIC programs

EVER DECREASING CIRCLES
Charles Pulteney concludes his look at graphics in BASIC with GSX
YYou'll need to have typed in the listing UTILITY.GSX given last month. This does nothing by itself but sets up graphics functions you can use in other programs. Enter your special GBASIC as usual, load UTILITY.GSX and type in Listing 1. This is a routine that draws circles, pie charts and pie slices. The mathematicians amongst you will realize that lines 6060-6120 plot a series of points five degrees apart around the arc of a circle. Straight lines drawn between these points provide a reasonable approximation to the curve of a circle (the lines are actually drawn by the polygon GOSUB). This is now your circle-drawing utility.
Listing 2 is all you need to draw any circle or pie chart. Furthermore, pie chart data will be automatically scaled with the size of each segment proportional to the sum of the data. In lines 10030 and 10080, the first two figures are the x and y co-ordinates (x1,y1) for the centre of the circle or pie chart. The third figure is the length of the radius, and the next is the number of segments. The data for each segment then follows. Each segment is drawn in clockwise order. Line 10060 is a clever way of automatically changing the fill pattern whenever a new segment is drawn (up to 12). Note that the slash is the integer division operator (press EXTRA and ½ twice). It is up to you to design your own segment labels! Unfortunately, you will find that the circle is not quite perfect. With large circles you will find that the radius at the top and bottom is slightly shorter than it ought to be. You will need to bear this in mind when drawing your labels.
Last month's introduction to GSX, the graphics drawing package supplied free with your PCW, left us all on the edge of our seats with bated breath and eyes agog. Now at last you can see some interesting and mindbogglingly useful applications: pie charts, bar graphs, circles...
Further reading
More details on GSX can be found in 'The Amstrad CP/M Plus' by Clarke and Powys-Libbe, but it's a real hacker's book, and won't enlighten you unless you're familiar with assembler. The same can be said lor Amsirad's 'CP/M Plus Handbook', by Digital Research, published by Heinemann at £14.95.
[BASIC listing]
[BASIC listing]
To draw a circle, the number of segments (no.segs%) should be set to 1 and the one item of data to 360. Do not forget to set fill% in line 10060 to 0 if you want a hollow circle. Save the program in the normal way and run it by merging with UTILITY.GSX and Listing 1.
Listing 3 draws a pie slice. The first two figures in line 10060 are the x and y co-ordinates for the point from which the slice is drawn. The third figure is the length of the radius, and the next two are the beginning and finishing points of the slice in degrees (ranging from to 360). Use fill% in line 10050 to set the fill. Save the program in the normal way and run it by merging with UTILITY.GSX.
Listing 4 draws a bar chart with a main title and labelled x and y axes. It may seem complicated, but this is because the program is designed to scale all data automatically, as well as to label axes, regardless of the size of the graph and the character height of the text selected. You will probably find it easier to follow this description of the key elements of the program if you type Listing 4 in now and run it.
[BASIC listing]
The core of the drawing is the window in which the bars are drawn. If you look at lines 10030 and 10380 you will see how the dimensions of the windows are set. The first four items in line 10380 provide the lower left and upper right co-ordinates of the window. The next two items in line 10380 specify the number of columns and the value of the largest column. The largest column will always extend to 75% of the height of the window (change 0.75 in line 10040, if you do not like this), and the other columns will automatically be scaled accordingly (by col.hgt). Lines 10070-10120 draw a scale on the y axis that is related to the value of the largest column (nxt.stp). Six proportional gradations are always drawn, the fifth of which is equal to the value of the largest column
The next three items in line 10380 provide the values of the character heights for the x axis text, the y axis text and the main title. The last two items are the main title, and the title of the y axis. Much of the complexity of the program is due to the fact that the titles and scales are drawn around the window. It is therefore necessary to keep track of the space that is used to draw text. This is not difficult to do because you can ask GSX to tell you how much space (width or height) is taken up by the characters of a particular character height setting. For example, in line 10190 hgt% is set to the height of the main title text and a call is made to GOSUB 8800. This call provides the value of the width of each character (ch.wth), which when divided by x.scale# is used in line 10200 to calculate the space taken up by the title. This information is then used to print the title in the centre of the large box at a position of gap3 above the top of the window. Similarly, ych.wth/x.scale# is used to centre the title of the y axis along the left side of the window (line 10160). The same technique is used to centre each x axis label on its bar (line 10260).
If you now change the first nine values of line 10380 to DATA 15,15,35,25,12,8000,1,1,1 you will find that a perfectly scaled mini-graph has been produced from the same data. In future, the effort required to produce this type of graph is minimal. You just change the relevant DATA lines!
Listing 5 introduces one other technique. Lines 8400-8710 of UTILITY.GSX alter the colour of fill, text, lines, and line markers. Setting colour% to 0 has the effect of writing in "white" and, for example, enables you to place "white" text on a black background, or to create a "white" shape within a filled shape. There are a number of points to note. First, when using the fill colour option, you have to specify the same fill setting that was used in the first place (line 10020). Second, the line effect is difficult to see as the tine is so narrow. Third, text, line markers and lines written when colour% is set to will not appear on the screen. Finally, do not forget to set colour% back to 1 and call the relevant GOSUB when you finish!
9512 owners beware
The GSX driver as shipped with the 9512 is a slightly improved version of the one 8000 machines have. With one exception, it performs the same. When using the draw rectangular box function with no fill, the 9512 driver erases everything written to the screen earlier on which falls within the boundaries of the box. In contrast, the 8256/8512 driver leaves the screen intact. This point is illustrated by line 10352 in BARCHART.GSX, listing 4. If the line is not changed and the 9512 driver is used, the rest of the picture willdisappear. This problem can be overcome by using the following lines:
10352 x1=llxout.box : y1=llout.box : x2=x1 : y2=uryout.box : gosub 4000
10353 x1=x1 : y1=y2 : *2=xx2+2 : y2=y2 : gosub 4000 : x1=x2 : y1=y2 : x2=x2 : y2=llyout.box : gosub 4000
10354 x1=x2 : y1=y2 : x2=llxout.box : y2=llyout.box : gosub 4000 : return
The line function is being used to draw the sides of the box. The variables 'llxout' and 'llyout' begin with letter is not number 1s.

[BASIC listing]
[BASIC listing]
Last month
These listings will mean nothing unless you have typed in the utilitiy given last month, if you want to get hold of last month's issue, back numbers are available from our Old Barn address for £1.75.
This is a demonstration listing to show off some of the effects possible from last month's UTILITY listing.
[BASIC listing]

HTML customization by Werner Cirsovius
February 2015
© 8000 PLUS