PyCairo – Drawing different Pen dashes
Each line can be drawn with different pen dashes. A pen dash can be defined as the style of a line. The dash pattern is specified by the set_dash( ) method. The pattern is set by the dash list which of floating value. They can set the on and off part of the dashes in pattern. The dashes is used by the stroke( ) method to create a line pattern. If the number of dashes is 0, dashing is disabled and a plane simple line will be drawn. If the number of dashes is 1, a symmetric pattern is assumed with alternative on and off portion of the size specified as the single values in dash.
Steps of Implementation :
- Import the Pycairo module.
- Create a SVG surface object and add context to it.
- Setting color of the context & line width
- Setting of line pattern using set_dash( )
- Creating a line.
Example 1 :
context.set_dash ( [ 4.0, 21.0, 2.0 ] )
We have 4 points drawn, 21 not drawn, and 2 drawn, then 4 points not drawn, 21 points drawn. and 2 not drawn.
Example 2 :
context.set_dash ( [ 14.0, 6.0 ] )
In this pattern, we have always 14 points drawn and 6 not drawn.
Example 3 :
context.set_dash ( [ 1.0 ] )
we create a pen dash of a symmetric pattern of alternating single on and off point.