p5.js displayDensity() Function
The displayDensity() function in p5.js is used to return the pixel density of the current display the sketch.
Syntax:
pixelDensity(density)
Parameters: This function accepts single parameter density which stores the display density.
Below program illustrates the displayDensity() function in p5.js:
Example:
function setup() {
createCanvas(windowWidth, windowHeight);
let density = displayDensity();
pixelDensity(density);
}
function draw() {
background(0, 200, 0);
color( "green" );
textSize(30);
textAlign(CENTER);
text( "GeeksForGeeks!" , windowWidth/2, windowHeight/2);
text( "PixelDensity is " + pixelDensity(),
windowWidth/2, windowHeight/2+40);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/displayDensity
Last Updated :
10 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...