Set the entire contents of np_pixels to the contents of another properly sized and typed numpy array.
import numpy as np def setup(): array = np.zeros((py5.height, py5.width, 3), dtype=np.uint8) array[:60, :, 0] = 200 array[:, :40, 1] = 100 array[20:, :, 2] = 250 py5.set_np_pixels(array, bands='RGB')
Set the entire contents of np_pixels to the contents of another properly sized and typed numpy array. The size of
array’s first and second dimensions must match the height and width of the Sketch window, respectively. The array’s
dtype must be
bands parameter is used to interpret the
array’s color channel dimension (the array’s third dimension). It can be one of
'L' (single-channel grayscale),
'RGBA'. If there is no alpha channel,
array is assumed to have no transparency, but recall that the display window’s pixels can never be transparent so any transparency in
array will have no effect. If the
bands parameter is
array’s third dimension is optional.
This method exists because setting the array contents with the code
py5.np_pixels = array will cause an error, while the correct syntax,
py5.np_pixels[:] = array, might also be unintuitive for beginners.
set_np_pixels( array: npt.NDArray[np.uint8], # properly sized numpy array to be copied to np_pixels bands: str = "ARGB", # color channels in the array's third dimension ) -> None
Updated on September 01, 2022 16:36:02pm UTC