User Guide
Ruby Component
Drawing Units
Before we begin we should quickly talk about the units of measurement we use for drawing. Because all drawing in FlowBotics Studio is
scalable we work in grid step units and not in pixels (see the Coordinates section in the chapter on Advanced GUI Editing). All coordinates,
measurements and sizes are in grid steps.
If you ever need to know the size of a grid square you can call the gridStep method on the View object at any time.
Pens, Brushes & Colors
Before you can draw anything you'll need either a Pen, a Brush or a Color. These are all represented by Ruby classes. Pens are used for
drawing lines and Brushes are used for filling areas. The Color class is used to define Pens and Brushes and as an input in other drawing
methods.
Color
You can't get anywhere without a Color so let's start here. Color objects are defined by three primary colour components (red, green and
blue) plus an optional transparency which is called Alpha. Each component is an integer value in thsete range 0-255.
To create a Color object:
myColor = Color.new a,r,g,b
Where a is the alpha, r is the red component, g is the green component and b is the blue component.
Here are some examples of creating Color objects.
c = Color.new 255,255,0,0 # an opaque red
c = Color.new 128,0,0,255 # a half transparent blue
c = Color.new 0,255,0 # an opaque green (no transparency)
c = Color.new 64 # a dark grey (a single value is a grayscale)
Pens
At their core, Pens are defined by a color and thickness (or width). They can also have a dash style, end caps like arrows or other shapes
and they can render their joints in a number of different ways. These are more advanced features that we'll look at later.
To create a Pen object:
myPen = Pen.new color, thickness
The color parameter is a Color object that you need to create and pass in. Thickness is the line width (again in grid steps, so this is usually a
number less than 1 for thinner lines).
If you need it, you can get the thickness or width of a pen object by calling the getWidth method. You can also set the width using the
setWidth method.
The colour can be set by calling the setColor method and passing a Color object.
Brushes
Brushes can be solid colours, textures, or gradients. The simplest brush is the solid brush. This is represented by the Brush class.
To create a Brush object:
myBrush = Brush.new color
Once again, the color parameter is a Color object that you need to create and pass in. As with pens, the colour can be set by calling the
setColor method and passing a Color object.
118 of 212