Py5Graphics.clear()#

Clears the pixels within a buffer.

Examples#

 1def setup():
 2    global pg
 3    py5.size(200, 200)
 4    pg = py5.create_graphics(py5.width, py5.height)
 5
 6
 7def draw():
 8    py5.background(204)
 9
10    # clear the Py5Graphics when the mouse is pressed
11    if py5.is_mouse_pressed:
12        pg.begin_draw()
13        pg.clear()
14        pg.end_draw()
15    else:
16        pg.begin_draw()
17        pg.stroke(0, 102, 153)
18        pg.line(py5.width//2, py5.height//2, py5.mouse_x, py5.mouse_y)
19        pg.end_draw()
20
21    py5.image(pg, 0, 0)

Description#

Clears the pixels within a buffer. Unlike the main graphics context (the display window), pixels in Py5Graphics objects created with create_graphics() can be entirely or partially transparent. This function clears everything in a Py5Graphics object to make all of the pixels 100% transparent.

Underlying Processing method: PGraphics.clear

Syntax#

clear() -> None

Updated on March 22, 2022 21:53:01pm UTC