loop()#

By default, py5 loops through draw() continuously, executing the code within it.

Examples#

 1x = 0
 2
 3
 4def setup():
 5    py5.size(200, 200)
 6    py5.no_loop()  # draw() will not loop
 7
 8
 9def draw():
10    global x
11    py5.background(204)
12    x = x + .1
13    if x > py5.width:
14        x = 0
15
16    py5.line(x, 0, x, py5.height)
17
18
19def mouse_pressed():
20    py5.loop()  # holding down the mouse activates looping
21
22
23def mouse_released():
24    py5.no_loop()  # releasing the mouse stops looping draw()

Description#

By default, py5 loops through draw() continuously, executing the code within it. However, the draw() loop may be stopped by calling no_loop(). In that case, the draw() loop can be resumed with loop().

Underlying Processing method: loop

Syntax#

loop() -> None

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