Thursday, September 4, 2025
HomeLanguagesJavascriptp5.js displayHeight Variable

p5.js displayHeight Variable

The displayHeight variable in p5.js is used to store the height of the screen display of the device. The value of height is stored according to the default pixelDensity. This variable is used to run a full-screen program on any display size. Multiply it with pixelDensity to return the actual screen size.

Syntax:

displayHeight

Parameters: This function does not accept any parameter.

Below program illustrates the displayHeight variable in p5.js:
Example-1:




function setup() {
    
    createCanvas(1000, 400);
    
    // Set text size to 40px
    textSize(20); 
}
  
function draw() {
    background(200);
    rect(mouseX, mouseY, 30, 30);
  
    //Use of displayHeight Variable
    text("Display Height is " + displayHeight, 30, 40);
}


Output:

Example-2:




function setup() {
  
    createCanvas(1000, displayHeight);
  
    // Set text size to 40px
    textSize(20);
}
  
function draw() {
  
    background(200);
    rect(mouseX, mouseY, 30, 30);
  
    //Use of displayHeight Variable
    text("Canvas Size of Display is displayHeight is " 
         + displayHeight, 30, 40);
}


Output:

Reference: https://p5js.org/reference/#/p5/displayHeight

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6746 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS