User Guide

Ruby Component
Advanced Brushes
The Drawing section covered how to create a solid brush and use it to fill basic shapes or draw text. In this section we'll look at more
advanced brush options.
Linear Gradients
You can create filled areas that flow smoothly between colours using the LinearGradientBrush class. This is a variation on the standard
Brush class and can be used as an instrument for drawing in all the shape drawing methods just like the standard Brush.
In its simplest form a LinearGradientBrush allows you to define a gradient between two colours. You create an instance of the class as
follows:
b = LinearGradientBrush.new boundRect, color1, color2, angle, scaleTrans
boundRect
This is a rectangle ( once again defined as a ruby array [x,y,width,height] ) that defines the boundary of the gradient fill. The gradient will fill
this area so you need to make sure that you create a bounding rectangle that fits with whatever shapes you intend to fill.
color1, color2
These are the end colours for the gradient and should be instances of the Color class. If you don't supply an angle parameter then color1 will
be at the left-hand edge of the rectangle and color2 will be at the right-hand edge.
angle
This is angle of rotation for the gradient in degrees in the clockwise direction. If the angle is 90 degrees for example, color1 will be at the top
of the rectangle and the gradient will run downwards to color2.
scaleTrans
This defines whether the angle is affected by the transform associated with the brush. The parameter is a boolean flag so it should be set to
true or false.
Here's a simple example of a LinearGradientBrush:
Transformations
You can rotate, translate or scale the brush after it has been created. To do this you use the following methods:
rotateTransform angle
129 of 212