no_loop()

Stops py5 from continuously executing the code within draw().

Examples

1
2
3
4
5
6
7
def setup():
    py5.size(200, 200)
    py5.no_loop()


def draw():
    py5.line(10, 10, 190, 190)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
x = 0.0


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


def draw():
    py5.background(204)
    global x
    x = x + 0.1
    if x > py5.width:
        x = 0
    py5.line(x, 0, x, py5.height)


def mouse_pressed():
    py5.no_loop()


def mouse_released():
    py5.loop()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
some_mode = False


def setup():
    py5.no_loop()


def draw():
    if some_mode:
        # do something
        pass


def mouse_pressed():
    some_mode = True
    py5.redraw()  # or call loop()

Description

Stops py5 from continuously executing the code within draw(). If loop() is called, the code in draw() begins to run continuously again. If using no_loop() in setup(), it should be the last line inside the block.

When no_loop() is used, it’s not possible to manipulate or access the screen inside event handling functions such as mouse_pressed() or key_pressed(). Instead, use those functions to call redraw() or loop(), which will run draw(), which can update the screen properly. This means that when no_loop() has been called, no drawing can happen, and functions like save_frame() or load_pixels() may not be used.

Note that if the Sketch is resized, redraw() will be called to update the Sketch, even after no_loop() has been specified. Otherwise, the Sketch would enter an odd state until loop() was called.

Underlying Java method: noLoop

Syntax

no_loop() -> None

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