Patterns - special fills
Martin McBride, 2020-08-01
Tags pattern
Categories generativepy generative art

In generativepy, shapes can be filled or stroked (outline) using solid colours or patterns.
Currently, the only pattern supported is linear gradient. More patterns will be supported in future versions.
Patterns make use of the following classes, in the geometry module:
LinearGradient
- defines a linear gradient.
Patterns all work in s similar way:
- The pattern is first constructed using the constructor and any required builder methods.
- The
build
method is then called to create the pattern.
The object returned by get_pattern
can be used in place of a Color
object when setting a stroke or fill.
See the patterns tutorial for examples.
LinearGradient
The LinearGradient
class defines a linear gradient.
Constructor
LinearGradient()
Creates a LinearGradient
object.
of_points
Sets the start and end points.
of_points(start, end)
Parameter | Type | Description |
---|---|---|
start | (number, number) | A tuple of two numbers, giving the (x, y) position of start point. |
end | (number, number) | A tuple of two numbers, giving the (x, y) position of end point. |
Specifies the start and end points of the gradient.
with_start_end
Sets the start and end colours.
with_start_end(start, end)
Parameter | Type | Description |
---|---|---|
start | Color | The first colour in the gradient. |
end | Color | The second colour in the gradient. |
Specifies the start and end colours of a simple two colour gradient.
This is a shortcut for
of_points([(0, start), (1, stop)])
A LinearGradient
should always have either with_start_end
or of_points
, but not both.
with_stops
Sets a list of colour stops.
with_stops(stops)
Parameter | Type | Description |
---|---|---|
stops | Sequence of stops | A list or tuple of stops (see below) |
Specifies individual stops in the gradient.
Each stop is a tuple of (position, color)
, where:
position
is the position within the gradient (0 for start, 1 for end, 0.5 for halfway etc).color
is the colour at that stop.
For example [(0, Color('black')), (0.5, Color('red')), (1, Color('blue'))]
goes from black to red to blue.
build
build()
Finalises the creation of the pattern. You must call this after all the construction steps, but before using the pattern.
get_pattern
get_pattern()
This method is used internally to get the Pycairo pattern object when the pattern is passed in to s Shape fill
or stroke
method.
You should not normally need to call this in your code.