Py5Graphics.update_pixels()

Updates the Py5Graphics drawing surface with the data in the Py5Graphics.pixels[] array.

Examples

example picture for update_pixels()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def setup():
    g = py5.create_graphics(60, 60)
    g.begin_draw()
    g.background(255, 0, 0)
    g.rect(10, 10, 40, 40)
    g.load_pixels()
    yellow = "#FF0"
    for i in range(len(g.pixels) // 2):
        g.pixels[i] = yellow
    g.update_pixels()
    g.end_draw()

    py5.background(240)
    py5.image(g, 20, 20)

Description

Updates the Py5Graphics drawing surface with the data in the Py5Graphics.pixels[] array. Use in conjunction with Py5Graphics.load_pixels(). If you’re only reading pixels from the array, there’s no need to call update_pixels() — updating is only necessary to apply changes.

Use the update_pixels(x, y, w, h) syntax to update only a subset of the pixel array. This can be faster if only some of the pixels have been changed.

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

Underlying Java method: PGraphics.updatePixels

Syntax

update_pixels() -> None
update_pixels(x: int, y: int, w: int, h: int, /) -> None

Parameters

  • h: int - height of pixel rectangle to update

  • w: int - width of pixel rectangle to update

  • x: int - x-coordinate of the upper left hand corner of rectangle to update

  • y: int - y-coordinate of the upper left hand corner of rectangle to update

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