Py5Shape.begin_shape()

Py5Shape.begin_shape()#

This method is used to start a custom shape created with the create_shape() function.

Examples#

def setup():
    global s  # the Py5Shape object
    s = py5.create_shape()
    s.begin_shape()
    s.fill("#F00")
    s.no_stroke()
    s.vertex(0, 0)
    s.vertex(0, 50)
    s.vertex(50, 0)
    s.end_shape()


def draw():
    py5.shape(s, 25, 25)
def setup():
    global s  # the Py5Shape object
    s = py5.create_shape()
    with s.begin_shape():
        s.fill("#F00")
        s.no_stroke()
        s.vertex(0, 0)
        s.vertex(0, 50)
        s.vertex(50, 0)


def draw():
    py5.shape(s, 25, 25)

Description#

This method is used to start a custom shape created with the create_shape() function. It’s always and only used with create_shape().

Drawing commands to a custom shape must always conclude with a call to the Py5Shape.end_shape() method. This method can be used as a context manager to ensure that Py5Shape.end_shape() always gets called, as shown in the second example. Use Py5Shape.begin_closed_shape() to create a context manager that will pass the CLOSE parameter to end_shape(), closing the shape.

Underlying Processing method: PShape.beginShape

Signatures#

begin_shape() -> None

begin_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