pixel_height#
Height of the display window in pixels.
Examples#
def setup():
py5.size(600, 400)
py5.pixel_density(2)
py5.println(py5.width, py5.height)
py5.println(py5.pixel_width, py5.pixel_height)
def setup():
py5.size(600, 400)
py5.pixel_density(2) # double the pixel density
py5.println(py5.width, py5.height)
py5.println(py5.pixel_width, py5.pixel_height)
def draw():
py5.load_pixels()
# fill all the pixels to blue with using
# pixel_width and pixel_height
for i in range(0, py5.pixel_width*py5.pixel_height):
py5.pixels[i] = "#00F"
# fill one quarter of the pixels to yellow
# because the pixel density is set to 2 in setup()
# and 'width' and 'height' don't reflect the pixel
# dimensions of the sketch
for i in range(0, py5.width*py5.height):
py5.pixels[i] = "#FF0"
py5.update_pixels()
py5.no_loop()
Description#
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 macOS 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_pixels(), 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 pixel_width*pixel_height
, not width*height
.
Underlying Processing field: pixelHeight
Updated on December 27, 2023 13:47:02pm UTC