redraw()#

Executes the code within draw() one time.

Examples#

 1x = 0
 2
 3
 4def setup():
 5    py5.size(200, 200)
 6    py5.no_loop()
 7
 8
 9def draw():
10    py5.background(204)
11    py5.line(x, 0, x, py5.height)
12
13
14def mouse_pressed():
15    x += 1
16    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 Processing method: redraw

Syntax#

redraw() -> None

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