16 Fill styles

class fill_style.T
This class determines the color and the pattern of the background of a region. Class fill_style.T itself is an abstract base class; actual drawing functions are provided by its subclassess, which are described later.

This class supports the following attributes:

bgcolor
Type: color.T ( see Section 15) Default: color.white.

The background color.

line_interval
Type: number Default: 3.

The interval between successive stitch lines.

line_style
Type: line_style.T ( see Section 14) Default: line_style.black.

The style of the line.

class fill_style.Plain
This class just fills the region with solid background color. Attributes line_style and line_interval are ignored.

class fill_style.Diag
This class fills the region with diagonal lines.

class fill_style.Rdiag
Fills the region with diagonal lines, but tilted in the opposite direction from fill_style.Diag.

class fill_style.Vert
Fills the region with vertical lines.

class fill_style.Horiz
Fills the region with horizontal lines.

class fill_style.Stitch
Fills the region with horizontal and vertical lines.

class fill_style.Wave
Fills the region with horizontal wavy lines.

class fill_style.Vwave
Fills the region with vertical wavy lines.

class fill_style.Lines
Fills the region with a series of short line segments.

The below picture shows the standard set of fill styles. They are named like fill_style.name, where name are the labels shown in the picture.

Image fillstyles

Just for your information, the "rdiag3" style shown in the picture can be created manually by the following code:

rdiag3 = fill_style.Rdiag(line_style=line_style.T(width=3, color=color.gray5),
                          line_interval=6)

You can create your own fill style by subtyping fill_style.T. It should provide the following public method:

draw( self, can, x1, y1, x2, y2)
This method is called to fill a rectangular region in a canvas. Parameter can is a canvas ( see Section 21), and region (x1,y1)-(x2,y2) specifies the region to be filled.

Just for your information, below is how the Rdiag class is implemented.

class Rdiag(fill_style.T):
    """Fills the region with diagonal lines, but tilted in the opposite
direction from fill_style.Diag."""
    def draw(self, can, x1, y1, x2, y2):    
        line_width = self.line_style.width
        interval = self.line_interval * 1.414
        x1 -= line_width
        y1 -= line_width
        x2 += line_width
        y2 += line_width
        len = max(y2 - y1, x2 - x1)
        while curx in range(x1, x2 + len, interval):
            can.line(self.line_style, curx, y1, curx-len, y1+len)