- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name | ### pixelDensity()
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);
    }
Description | This function is new with Processing 3.0. It makes it possible for Processing 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 and it must be used right after size() in a program without a setup() and used within setup() when a program has one. The 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 all of 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.
Syntax |
    pixelDensity(density)
Parameters |
density | int: 1 or 2
Returns | void
Related | pixelWidth pixelHeight

Updated on January 9, 2020 00:33:07pm EST