Py5Shape.begin_contour()#

Use the begin_contour() and Py5Shape.end_contour() methods to create negative shapes within a Py5Shape object such as the center of the letter ‘O’.

Examples#

example picture for begin_contour()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3    s = py5.create_shape()
 4    s.begin_shape()
 5    # exterior part of shape, clockwise winding
 6    s.vertex(20, 20)
 7    s.vertex(80, 20)
 8    s.vertex(80, 80)
 9    s.vertex(20, 80)
10    # interior part of shape, counter-clockwise winding
11    s.begin_contour()
12    s.vertex(40, 40)
13    s.vertex(40, 60)
14    s.vertex(60, 60)
15    s.vertex(60, 40)
16    s.end_contour()
17    s.end_shape(py5.CLOSE)
18    py5.shape(s)
example picture for begin_contour()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3    s = py5.create_shape()
 4    with s.begin_closed_shape():
 5        # exterior part of shape, clockwise winding
 6        s.vertex(20, 20)
 7        s.vertex(80, 20)
 8        s.vertex(80, 80)
 9        s.vertex(20, 80)
10        # interior part of shape, counter-clockwise winding
11        with s.begin_contour():
12            s.vertex(40, 40)
13            s.vertex(40, 60)
14            s.vertex(60, 60)
15            s.vertex(60, 40)
16
17    py5.shape(s)

Description#

Use the begin_contour() and Py5Shape.end_contour() methods to create negative shapes within a Py5Shape object such as the center of the letter ‘O’. The begin_contour() method begins recording vertices for the shape and Py5Shape.end_contour() stops recording. The vertices that define a negative shape must “wind” in the opposite direction from the exterior shape. First draw vertices for the exterior shape in clockwise order, then for internal shapes, draw vertices counterclockwise.

These methods can only be used within a Py5Shape.begin_shape() & Py5Shape.end_shape() pair and transformations such as Py5Shape.translate(), Py5Shape.rotate(), and Py5Shape.scale() do not work within a begin_contour() & Py5Shape.end_contour() pair. It is also not possible to use other shapes, such as ellipse() or rect() within.

This method can be used as a context manager to ensure that Py5Shape.end_contour() always gets called, as shown in the second example.

Underlying Processing method: PShape.beginContour

Syntax#

begin_contour() -> None

Updated on November 12, 2021 11:30:58am UTC