Sinclair QL Beginner's Manual page 43

Hide thumbs Also See for QL:
Table of Contents

Advertisement

PASSING INFORMATION TO PROCEDURES
Suppose we wish to draw squares of various sizes and various colours in various positions on the
scale graphics screen.
If we define a procedure, "square", to do this it will require four items of information:
length of one side
colour (colour code)
position (across and up)
The square's position is determined by giving two values, across and up, which fix the bottom left
hand corner of the square as shown below.
The colour of the square is easily fixed but the square itself uses the values of side and ac and up as
follows.
200 DEFine PROCedure square(side,ac,up)
210
LINE ac,up TO ac+side,up
220
LINE TO ac+side,up+side
230
LINE TO ac,up+side TO ac,up
240 END DEFine
In order to make this procedure work values of side, ac and up must be provided. These values are
provided when the procedure is called. For example you could add the following main program to get
one green square of side 20.
100 PAPER 7:CLS
110 INK 4
120 square 20,50,50
The numbers 20,50,50 are called parameters and they are passed to the variables named in the
procedure definition thus:
The numbers 20,50,50 are called actual parameters. They are numbers in this case but they could
be variables or expressions. The variables side, ac, up are called formal parameters. They must be
variables because they 'receive' values.
A more interesting main program uses the same procedure to create a random pattern of coloured
pairs of squares. Each pair of squares is obtained by offsetting the second one across and up by one-
fifth of the side length thus:

Advertisement

Table of Contents
loading

Table of Contents