loop()

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
x = 0


def setup():
    py5.size(200, 200)
    py5.no_loop()  # draw() will not loop


def draw():
    global x
    py5.background(204)
    x = x + .1
    if x > py5.width:
        x = 0

    py5.line(x, 0, x, py5.height)


def mouse_pressed():
    py5.loop()  # holding down the mouse activates looping


def mouse_released():
    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 Java method: loop

Syntax

loop() -> None

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