This function makes it possible for py5 to render using all of the pixels on high resolutions screens like Apple Retina displays and Windows High-DPI displays.
1 2 3 4 5 6 7 8 9
def setup(): py5.pixel_density(2) py5.no_stroke() def draw(): py5.background(0) py5.ellipse(30, 48, 36, 36) py5.ellipse(70, 48, 36, 36)
1 2 3 4 5 6 7 8 9 10
def setup(): py5.pixel_density(py5.display_density()) # pulling the display's density dynamically py5.no_stroke() def draw(): py5.background(0) py5.ellipse(30, 48, 36, 36) py5.ellipse(70, 48, 36, 36)
This function makes it possible for py5 to render using all of the pixels on high resolutions screens like Apple Retina displays and Windows High-DPI displays. This function can only be run once within a program. It is intended to be called from the
When programming in module mode and imported mode, py5 will allow calls to
pixel_density() from the
setup() function if it is called at the beginning of
setup(). This allows the user to omit the
settings() function, much like what can be done while programming in the Processing IDE. Py5 does this by inspecting the
setup() function and attempting to split it into synthetic
setup() functions if both were not created by the user and the real
setup() function contains a call to
pixel_density(), or calls to size(), full_screen(), smooth(), or no_smooth(). Calls to those functions must be at the very beginning of
setup(), before any other Python code (but comments are ok). This feature is not available when programming in class mode.
pixel_density() should only be used with hardcoded numbers (in almost all cases this number will be 2) or in combination with display_density() as in the second example.
When the pixel density is set to more than 1, it changes all of the pixel operations including the way get(), blend(), copy(), update_pixels(), and update_np_pixels() all work. See the reference for pixel_width and pixel_height for more information.
Underlying Processing method: pixelDensity
pixel_density(density: int, /) -> None
density: int - 1 or 2
Updated on November 12, 2021 11:30:58am UTC