Py5Graphics.begin_draw()#

Sets the default properties for a Py5Graphics object.

Examples#

example picture for begin_draw()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3
 4    g = py5.create_graphics(60, 60, py5.P2D)
 5    g.begin_draw()
 6    g.translate(30, 30)
 7    g.begin_shape()
 8    g.vertex(-10, -10)
 9    g.vertex(10, -10)
10    g.vertex(10, 10)
11    g.vertex(-10, 10)
12    g.end_shape(py5.CLOSE)
13    g.end_draw()
14
15    py5.image(g, 0, 0)
16    py5.image(g, 25, 25)
example picture for begin_draw()
 1def setup():
 2    py5.size(100, 100, py5.P2D)
 3
 4    g = py5.create_graphics(60, 60, py5.P2D)
 5    with g.begin_draw():
 6        g.translate(30, 30)
 7        with g.begin_closed_shape():
 8            g.vertex(-10, -10)
 9            g.vertex(10, -10)
10            g.vertex(10, 10)
11            g.vertex(-10, 10)
12
13    py5.image(g, 0, 0)
14    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 Processing method: PGraphics.beginDraw

Syntax#

begin_draw() -> None

Updated on November 12, 2021 11:30:58am UTC