Paths

The final fundamental graphical object type is Path, which allows drawing arbitrary shapes using lines and curves.

path = Path(ORIGIN, None, "#ff00ff55")
path.line_to(Mm(10), Mm(-10))
path.line_to(Mm(20), Mm(0))
path.line_to(Mm(30), Mm(-10))
path.cubic_to(Mm(40), Mm(-10), Mm(40), Mm(10), Mm(30), Mm(10))
/_static/rendered_examples/QQV7GBHVEHQXOIFZN2MEVTMJRTNDE5NZ.png

(The brushes and pens used to fill and outline shapes will be covered in the next section)

Paths are drawn by calling the various drawing methods. Path.line_to draws a straight line from the current drawing position. Path.cubic_to similarly draws a bezier curve. Path.move_to breaks off the current subpath and starts a new one at a given position. Path.close_subpath connects a line to the current subpath’s starting position.

By default, the positions passed to these drawing operations are relative to the path itself. The created path elements can be attached to other objects using the various parent arguments.

text = Text((Mm(50), Mm(-10)), None, "a parent")
path = Path(ORIGIN, None, "#0000ff55")
path.line_to(Mm(-1), Mm(1), text)
path.line_to(Mm(-1), Mm(12), text)
path.close_subpath()
/_static/rendered_examples/IBBCJPJZPGZAB5L7K2XNSG7WB3BI3C2J.png

Path provides several convenience constructors for drawing common shapes including: