redraw()

Executes the code within draw() one time.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x = 0


def setup():
    py5.size(200, 200)
    py5.no_loop()


def draw():
    py5.background(204)
    py5.line(x, 0, x, py5.height)


def mouse_pressed():
    x += 1
    py5.redraw()

Description

Executes the code within draw() one time. This functions allows the program to update the display window only when necessary, for example when an event registered by mouse_pressed() or key_pressed() occurs.

In structuring a program, it only makes sense to call redraw() within events such as mouse_pressed(). This is because redraw() does not run draw() immediately (it only sets a flag that indicates an update is needed).

The redraw() function does not work properly when called inside draw(). To enable/disable animations, use loop() and no_loop().

Underlying Java method: redraw

Syntax

redraw() -> None

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