pixels array contains the values for all the pixels in the Py5Graphics drawing surface.
1def setup(): 2 g = py5.create_graphics(60, 60) 3 g.begin_draw() 4 g.background(255, 0, 0) 5 g.rect(10, 10, 40, 40) 6 g.load_pixels() 7 yellow = "#FF0" 8 for i in range(len(g.pixels) // 2): 9 g.pixels[i] = yellow 10 g.update_pixels() 11 g.end_draw() 12 13 py5.background(240) 14 py5.image(g, 20, 20)
pixels array contains the values for all the pixels in the Py5Graphics drawing surface. These values are of the color datatype. This array is defined by the size of the Py5Graphics drawing surface. For example, if the drawing surface is 100 x 100 pixels, there will be 10,000 values and if the drawing surface is 200 x 300 pixels, there will be 60,000 values. When the pixel density is set to higher than 1 with the Py5Graphics.pixel_density function, these values will change. See the reference for Py5Graphics.pixel_width or Py5Graphics.pixel_height for more information.
Before accessing this array, the data must loaded with the Py5Graphics.load_pixels() function. Failure to do so may result in a Java
NullPointerException. Subsequent changes to the Py5Graphics drawing surface will not be reflected in
pixels until Py5Graphics.load_pixels() is called again. After
pixels has been modified, the Py5Graphics.update_pixels() function must be run to update the content of the Py5Graphics drawing surface.
This field is the same as pixels but linked to a
Underlying Processing field: PGraphics.pixels
Updated on November 12, 2021 11:30:58am UTC