Reference+
Name
pixelDensity()
Description
This function makes it possible to render using all the pixels on high resolutions screens like Apple Retina and Windows HiDPI. This function can only be run once within a program, and must be called right after size() in a program without a setup() function, or within setup() if present.
pixelDensity() should only be used with hardcoded numbers (in almost all cases this number will be 2) or in combination with displayDensity() as in the third example above. When the pixel density is set to more than 1, it changes the pixel operations including the way get(), set(), blend(), copy(), and updatePixels() all work. See the reference for pixelWidth and pixelHeight for more information. To use variables as the arguments to pixelDensity() function, place the pixelDensity() function within the settings() function. There is more information about this on the settings() reference page.Examples
size(100, 100); pixelDensity(2); noStroke(); background(0); ellipse(30, 48, 36, 36); ellipse(70, 48, 36, 36);
void setup() { size(100, 100); pixelDensity(2); noStroke(); } void draw() { background(0); ellipse(30, 48, 36, 36); ellipse(70, 48, 36, 36); }
void setup() { size(100, 100); // Pulling the display's density dynamically pixelDensity(displayDensity()); noStroke(); } void draw() { background(0); ellipse(30, 48, 36, 36); ellipse(70, 48, 36, 36); }
Syntax
pixelDensity(density)
Parameters
density
(int)
1 or 2
Return
void
Related
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.