Py5Graphics.load_np_pixels()

Py5Graphics.load_np_pixels()#

Loads the pixel data of the current Py5Graphics drawing surface into the Py5Graphics.np_pixels[] array.

Examples#

example picture for load_np_pixels()

def setup():
    g = py5.create_graphics(80, 80)
    g.begin_draw()
    g.background(255)
    g.rect(10, 10, 60, 60)
    g.load_np_pixels()
    g.np_pixels[:, 40:, 1:] = [255, 0, 0]
    g.update_np_pixels()
    g.end_draw()
    py5.image(g, 10, 10)

Description#

Loads the pixel data of the current Py5Graphics drawing surface into the Py5Graphics.np_pixels[] array. This method must always be called before reading from or writing to Py5Graphics.np_pixels[]. It should only be used between calls to Py5Graphics.begin_draw() and Py5Graphics.end_draw(). Subsequent changes to the Py5Graphics drawing surface will not be reflected in Py5Graphics.np_pixels[] until load_np_pixels() is called again.

The load_np_pixels() method is similar to Py5Graphics.load_pixels() in that load_np_pixels() must be called before reading from or writing to Py5Graphics.np_pixels[] just as Py5Graphics.load_pixels() must be called before reading from or writing to Py5Graphics.pixels[].

Note that load_np_pixels() will as a side effect call Py5Graphics.load_pixels(), so if your code needs to read Py5Graphics.np_pixels[] and Py5Graphics.pixels[] simultaneously, there is no need for a separate call to Py5Graphics.load_pixels(). However, be aware that modifying both Py5Graphics.np_pixels[] and Py5Graphics.pixels[] simultaneously will likely result in the updates to Py5Graphics.pixels[] being discarded.

This method is the same as load_np_pixels() but linked to a Py5Graphics object.

Signatures#

load_np_pixels() -> None

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