Py5Graphics.begin_closed_shape()

Py5Graphics.begin_closed_shape()#

This method is used to start a custom closed shape.

Examples#

example picture for begin_closed_shape()

def setup():
    py5.size(100, 100, py5.P2D)

    g = py5.create_graphics(60, 60, py5.P2D)
    with g.begin_draw():
        with g.begin_closed_shape():
            g.vertex(10, 10)
            g.vertex(50, 10)
            g.vertex(50, 50)
            g.vertex(10, 50)
            with g.begin_contour():
                g.vertex(20, 20)
                g.vertex(20, 40)
                g.vertex(40, 40)
                g.vertex(40, 20)

    py5.image(g, 0, 0)
    py5.image(g, 25, 25)

Description#

This method is used to start a custom closed shape. This method should only be used as a context manager, as shown in the example. When used as a context manager, this will ensure that Py5Graphics.end_shape() always gets called, just like when using Py5Graphics.begin_shape() as a context manager. The difference is that when exiting, the parameter CLOSE will be passed to Py5Graphics.end_shape(), connecting the last vertex to the first. This will close the shape. If this method were to be used not as a context manager, it won’t be able to close the shape by making the call to Py5Graphics.end_shape().

This method is the same as begin_closed_shape() but linked to a Py5Graphics object.

Underlying Processing method: PGraphics.beginShape

Signatures#

begin_closed_shape() -> None

begin_closed_shape(
    kind: int,  # Either POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP
    /,
) -> None

Updated on March 06, 2023 02:49:26am UTC