Py5Graphics.begin_draw()

Sets the default properties for a Py5Graphics object.

Examples

example picture for begin_draw()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def setup():
    py5.size(100, 100, py5.P2D)

    g = py5.create_graphics(60, 60, py5.P2D)
    g.begin_draw()
    g.translate(30, 30)
    g.begin_shape()
    g.vertex(-10, -10)
    g.vertex(10, -10)
    g.vertex(10, 10)
    g.vertex(-10, 10)
    g.end_shape(py5.CLOSE)
    g.end_draw()

    py5.image(g, 0, 0)
    py5.image(g, 25, 25)
example picture for begin_draw()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def setup():
    py5.size(100, 100, py5.P2D)

    g = py5.create_graphics(60, 60, py5.P2D)
    with g.begin_draw():
        g.translate(30, 30)
        with g.begin_closed_shape():
            g.vertex(-10, -10)
            g.vertex(10, -10)
            g.vertex(10, 10)
            g.vertex(-10, 10)

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

Description

Sets the default properties for a Py5Graphics object. It should be called before anything is drawn into the object. After the drawing commands have concluded, call Py5Graphics.end_draw() to finalize the Py5Graphics object.

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

Underlying Java method: PGraphics.beginDraw

Syntax

begin_draw() -> None

Updated on September 25, 2021 10:33:52am UTC