In this tutorial we are going to introduce brushes. These are similar to pens in that they are part of the graphics context and a new brush is created as a modification of an existing brush - using the same syntax.
In the earlier tutorial on filling, the shapes were filled with grey. This is because the default brush is grey.
Creating a New Brush
The following shows the declaration of a new brush which is initialised from the default brush but with a new colour.
[= within a declaration section of a shape routine=] TBrush greenbrush = Brush { colour -> { 0, 100, 0 } }; [= within the code section of a shape routine =] Circle(30, Filled) => {160, 100}, greenbrush;gctx_brush_1.grs
The next example shows that you can use the brush within a With statement to affect more than one shape.
With workpen, workbrush Do [= a series of shape calls =] EndWith;gctx_brush_2.grs
Opacity
In a previous section I said that a Colour had three components ( red, green an blue ) - there is in fact a fourth component. This is the opacity. It affect how well the new colour covers what was originally on the canvas. The default value is 100% - I.e. it will completely obscure what is under it.
In the following example I am only using each brush once so there is no need to declare a variable to hold it. You can just provide an expression that yields a brush and use that ( rather like when we used a function the returned a point to be used as the origin ). Note: if you do want to use something complex like a brush more than once it is better to create a variable to hold it.
The full example uses three different opacity values to demonstrate the effect more clearly.
[= opacity set to 50% =] Circle(30, Filled) => {160, 100}, Brush { colour -> { 0, 100, 0, 50 } };gctx_brush_3.grs