Py5Shape.begin_shape()

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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 Java method: PShape.beginShape

Syntax

begin_shape() -> None
begin_shape(kind: int, /) -> None

Parameters

  • kind: int - Either POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, or QUAD_STRIP

Updated on October 29, 2021 22:01:43pm UTC