18.3. Polyline - main line drawing primitive.   



Polyline(N,X,Y)
Note we will use a high level notation for the routines allowing
spaces in names.
N is number of points (X[1],Y[1]) to (X[N],Y[N])
N is of type integer and X,Y are variables sized arrays of reals.
This concept allows efficient drawing of n-1 line segments on most devices at
the expense of storage required for the array. Is this a real problem?

The arrays may be set up via assignment statements

X[i] := minX + (maxX - minX)*i/255
Y[i] := f(X[i]);

or read in from a data file

FOR i:= 1 TO 100 DO
readln(X[i],Y[i]);


A call to polyline will then plot the line segments defined by the two arrays.

Notice that we do not have any specific "Move" primitive. This is done
automatically
- move to (X[1],Y[1]) and then draw to (X[2],Y[2]) and subsequent points.
There is no current position concept - the pen or drawing position is only
relevant when a primitive is executed not before or after.

18.3.1. Polyline Attributes.   

When graphing data it might be nice to differentiate between different plots or between the plot and the axes.


 
Polyline plots
Fig. 18.1 : Polyline plots
To do this we need to be able to set the line drawing attribute. This is done via
set polyline index (N)
where the current line drawing attribute is set to N until a subsequent call to set polyline index (M).

Index 1 may be solid - default
2 may be dashed
3 may be dotted
4 may be dash-dotted
set polyline index (1); polyline (N,X1,Y1)
set polyline index (2); polyline (M,X2,Y2)

What else is appropriate to polyline? (i.e. other attributes).
Line width : device specific but GKS allows us to specify a relative size: we can set a line width scale factor: real number giving the width of the line relative to the width of a standard line on this device.
Lw < 1 thinner than standard line
Lw > 1 thicker than standard line

Colour : colour of line is important and this can be set as can the line width by a call to


set polyline representation(WS, PLI, LT, LW, PLCI)
WS is workstation in question.
PLI is number of polyline index
LT is line type
LW is line width
PLCI is polyline colour INDEX

The colour is not defined by a value but by an index into a table of colours: 3 entries for intensities of RED, GREEN, BLUE = colour lookup table.

(For pens in plotter may be 0 = white
1 = blank
2 = red etc.).

Three polyline indices for one workstation could represent solid, dashed and dotted lines with the same three indices giving red, green, and blue lines on a workstation that was a plotter. (NOTE the polyline index could be the same on the different workstations but GKS does allow us the flexibility).

GKS allows the user to setup the colour lookup table for different workstations: set colour representation (WS, CI, R, G, B)

Where CI is colour index and R, G, B are real values between 0 and 1 representing the intensities of the Red, Green and Blue colours.


R G B
what is black? 0 0 0
white? 1 1 1
yellow? 1 1 0 Red and Green
blue? 0 0 1