4.5 Stroke

A very powerful way of defining shapes is by applying a stroke to a previously defined shape. The metaphor for stroke is that a scalpel is moved parallel to the segments of the shape definition, at a specified distance perpendicular to the segments:

Figure 8: Stroke operation applied to an open shape

openStroke: @Shape
  (# 
  do (100, 100) -> open;
     (150,  50) -> lineTo;
     (200, 100) -> lineTo;
     (250,  50) -> lineTo;
     (300, 100) -> splineTo;
     (350,  50) -> splineTo;
     (400, 100) -> splineTo;
     (10, CapButt, JoinMiter) -> stroke;
  #);
[45 bytes 50x5 GIF]

Resulting Shape:

[2kb 207x72 GIF]

In the Figure above, the dashed curve is the original shape which consists of three line segments and one spline segment with four control points (the control points are not shown). The resulting shape is the outline made by the scalpel. The scalpel starts (and ends) in the leftmost top corner. The orientation of the resulting shape is indicated with arrows along the segments. Notice that the shape is closed after the operation has been applied.

A closed shape is stroked likewise but with no need to make special ends:

Figure 9: The stroke operation applied to a closed shape

closedStroke: @Shape
  (# 
  do ( 50, 100) -> open;
     (200, 100) -> lineTo;
     (200,  50) -> lineTo;
     ( 50,  50) -> lineTo;
     close;
     (10, CapButt, JoinMiter) -> stroke;
  #);
[45 bytes 50x5 GIF]

Resulting Shape:

[1kb 172x69 GIF]

Notice the different orientation of the outer and inner shapes, and that the resulting shape consists of two shapes (or more precisely: the shape consists of four line segments and one shape - also consisting of four line segments)

When the stroke operation has been applied, the original shape is altered and cannot be restored but only the new shape can be manipulated (i.e. the segments of the original shape are irreversibly replaced with the segments that define the new stroked shape). This is different from traditional graphics systems like PostScript, where the original shape (or path in PostScript terms) is unchanged and the stroke only makes a temporary outline which is discharged after having been used for filling an area of the drawing surface. Notice particularly, that the stroke of a spline segment results in two parallel spline segments. This is a completely new idea, since the traditional graphics systems can avoid calculating new spline control points by approximating the spline with a polygon before calculating the temporary outline (the traditional models do not need the new splines since the temporary outline is immediately discarded without giving the user the possibility to transform or modify the stroked spline).

The advantage of altering the shape is that it then becomes possible to further manipulate the shape, and that the shape can be used for other purposes than just drawing it, e.g. clip to the shape, detect mouse clicks within the shape etc.

4.5.1 Cap and Join Styles

The Cap parameter to the Stroke operation determines how the resulting shape looks in the part of it corresponding to the end point of the original shape. The Cap parameter is only relevant for open shapes. The Join parameter determines how the line parts of the shape are joined. In the example above for an open shape, the Cap parameter is CapButt specifying a line perpendicular to the shape and the Join parameter in both examples is JoinMiter. The alternatives are illustrated in the Figure below.

Figure 10: Cap and join styles for the Stroke operation

[2kb 262x121 GIF]


The Bifrost Graphics System - Reference Manual
© 1991-2004 Mjølner Informatics
[Modified: Tuesday October 24th 2000 at 22:29]