pixel_height

Height of the display window in pixels.

Examples

1
2
3
4
5
def setup():
    py5.size(600, 400)
    py5.pixel_density(2)
    py5.println(py5.width, py5.height)
    py5.println(py5.pixel_width, py5.pixel_height)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 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 pixel_width*pixel_height, not width*height.

Underlying Java field: pixelHeight

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