begin_closed_shape()

This method is used to start a custom closed shape.

Examples

example picture for begin_closed_shape()
1
2
3
4
5
6
7
def setup():
    py5.translate(50, 50)
    with py5.begin_closed_shape():
        py5.vertex(-40, -40)
        py5.vertex(40, -40)
        py5.vertex(40, 40)
        py5.vertex(-40, 40)
example picture for begin_closed_shape()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def setup():
    py5.translate(25, 50)
    py5.stroke_weight(4)
    py5.stroke("#F00")
    with py5.begin_closed_shape():
        py5.vertex(-20, -40)
        py5.vertex(20, -40)
        py5.vertex(20, 40)
        py5.vertex(-20, 40)

    py5.translate(50, 0)
    py5.stroke("#00F")
    with py5.begin_shape():
        py5.vertex(-20, -40)
        py5.vertex(20, -40)
        py5.vertex(20, 40)
        py5.vertex(-20, 40)

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 examples. When used as a context manager, this will ensure that end_shape() always gets called, just like when using begin_shape() as a context manager. The difference is that when exiting, the parameter CLOSE will be passed to 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 end_shape().

Underlying Java method: beginShape

Syntax

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

Parameters

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

Updated on September 23, 2021 10:53:31am UTC