Py5Graphics.clear()

Clears the pixels within a buffer.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def setup():
    py5.size(200, 200)
    global pg
    pg = py5.create_graphics(py5.width, py5.height)


def draw():
    py5.background(204)

    # clear the Py5Graphics when the mouse is pressed
    if py5.is_mouse_pressed:
        pg.begin_draw()
        pg.clear()
        pg.end_draw()
    else:
        pg.begin_draw()
        pg.stroke(0, 102, 153)
        pg.line(py5.width//2, py5.height//2, py5.mouse_x, py5.mouse_y)
        pg.end_draw()

    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 Java method: PGraphics.clear

Syntax

clear() -> None

Updated on September 11, 2021 16:51:34pm UTC