Friday, February 6, 2026
HomeLanguagesJavascriptp5.js windowHeight

p5.js windowHeight

The windowHeight in p5.js is a system variable that is used to store the height of the inner window and it maps to window.innerHeight.
Syntax

windowHeight

Parameters: This function does not accept any parameter.

Below program illustrates the windowHeight 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 windowHeight Variable
    text("Window Height is " + windowHeight, 30, 40);
}


Output:

Example-2:




function setup() {
  
    // set height to window height 
    height = windowHeight;
  
    //create Canvas of size 380*80 
    createCanvas(380, height);
}
  
function draw() {
    background(220);
    textSize(16);
    textAlign(CENTER);
    fill(color('Green'));
  
    //use of windowHeight variable
    text("windowHeight of Canvas is : "
         + height, 180, height / 2);
}


Output:

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

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
32491 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11985 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12074 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6931 POSTS0 COMMENTS