no_loop()

no_loop()#

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

Examples#

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


def draw():
    py5.line(10, 10, 190, 190)
x = 0.0


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


def draw():
    global x
    py5.background(204)
    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()
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 Processing method: noLoop

Signatures#

no_loop() -> None

Updated on March 06, 2023 02:49:26am UTC