Tutorial - Pens

In this section we will start looking at the pens. A pen is implemented as a structured record type. In order to understand fully the syntax of the pens it is necessary to cover structures in detail - but that would be a long and tedious digression. Therefore I am just going to jump in and for now you will just have to learn the syntax as we go along.

The Graphics Context

We have already mentioned the graphics context when we covered the origin. The pen is another object in the graphics context. All shape routines are executed within a graphics context. When the program starts there will be a default pen with a number of properties. The line width will be 1 and the colour black.

Creating a New Pen

You always generate a new pen based on an existing pen. The default pen is always call Pen.

you can declare a new pen by declaring a variable with type TPen. This will create a Null pen. We shall give it a values based on the default pen ( the only one we have as yet ).

The syntax is rather odd :-

	thickpen := Pen { width -> 5 };
	Circle(40) => {200, 100}, thickpen;
gctx_pen_1.grs Output of gctx_pen_1.grs gctx_pen_1.png





In the statement where the pen is set the "{" can be seen as analogous to the "(" in a function call and the values with the braces can be viewed as the parameters. Instead of a function to the left of the "{" there is an existing structure. ( as the width is the first field you could even do "Pen{5}" - but I would not recommend it for beginners ).

It is possible to change several parameters with a single call.

	thickpen := Pen { width -> 5, colour -> {100, 0, 0} };
	Circle(40) => {200, 100}, thickpen;
gctx_pen_2.grs Output of gctx_pen_2.grs gctx_pen_2.png

To get the system to use the new pen when drawing a shape just place the name of the pen after the "=>" with the other context information ( i.e. the origin ).

You can even use the new pen with the 'With' construct.

	With thickpen Do

		{= some code =]
	
	EndWith;

Colours

In the preceding example we set the colour to be "{100, 0, 0}". This is a saturation triplet. Any colour can be made up from red, green and blue. The set of three number represent the percentage saturation of each of the three primary colours ( 100% red and 0% green and blue ).

The colour type actually has a fourth field, the opacity or alpha value, which will default to 100% and can be ignored for now.