Height of the display window in pixels.
1def setup(): 2 py5.size(600, 400) 3 py5.pixel_density(2) 4 py5.println(py5.width, py5.height) 5 py5.println(py5.pixel_width, py5.pixel_height)
1def setup(): 2 py5.size(600, 400) 3 py5.pixel_density(2) # double the pixel density 4 py5.println(py5.width, py5.height) 5 py5.println(py5.pixel_width, py5.pixel_height) 6 7 8def draw(): 9 py5.load_pixels() 10 # fill all the pixels to blue with using 11 # pixel_width and pixel_height 12 for i in range(0, py5.pixel_width*py5.pixel_height): 13 py5.pixels[i] = "#00F" 14 15 # fill one quarter of the pixels to yellow 16 # because the pixel density is set to 2 in setup() 17 # and 'width' and 'height' don't reflect the pixel 18 # dimensions of the sketch 19 for i in range(0, py5.width*py5.height): 20 py5.pixels[i] = "#FF0" 21 22 py5.update_pixels() 23 py5.no_loop()
Height of the display window in pixels. When
pixel_density(2) is used to make use of a high resolution display (called a Retina display on OSX or high-dpi on Windows and Linux), the width and height of the Sketch do not change, but the number of pixels is doubled. As a result, all operations that use pixels (like load_pixels(), get(), etc.) happen in this doubled space. As a convenience, the variables pixel_width and
pixel_height hold the actual width and height of the Sketch in pixels. This is useful for any Sketch that use the pixels or np_pixels arrays, for instance, because the number of elements in each array will be
Underlying Processing field: pixelHeight
Updated on November 12, 2021 11:30:58am UTC