Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js | displayDensity() Function

Improve Article
Save Article
  • Last Updated : 09 Jul, 2019
Improve Article
Save Article

The displayDensity() function in p5.js is used to return the pixel density of the current display the sketch.



Parameters: This function accepts single parameter density which stores the display density.

Below program illustrates the displayDensity() function in p5.js:


function setup() {
    // Create canvas of given size
    createCanvas(windowWidth, windowHeight);
    // Call the displayDensity function
    let density = displayDensity(); 
function draw() {
    // Set the background color
    background(0, 200, 0);
    // Set text color
    // Set font size
    // Set text alignment
    // Set text to be add
    text("GeeksForGeeks!", windowWidth/2, windowHeight/2);
    // Display pixelDensity on the screen
    text("PixelDensity is " + pixelDensity(), 
            windowWidth/2, windowHeight/2+40);



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!