p5.js | height variable
The height variable in p5.js is a system variable which stores the height of the drawing canvas. It sets the second parameter of createCanvas() function.
Syntax:
height
Below programs illustrate the height variable in p5.js:
Example 1: This example uses height variable to display the height of canvas.
function setup() { // Create Canvas of size 380*80 createCanvas(380, 80); } function draw() { // Set the background color background(220); // Set the text size textSize(16); // Set the text alignment textAlign(CENTER); // Set the text color fill(color('Green')); // Display result text("Height of Canvas is : " + height, 180, 50); } |
Output:

Example 2: This example uses height variable to display the height of window.
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')); text("Height of Canvas is : "+height, 180, height/2); //use of height variable } |
Output:

Reference: https://p5js.org/reference/#/p5/height
Recommended Posts:
- variable === undefined vs. typeof variable === “undefined” in JavaScript
- p5.js | displayHeight Variable
- p5.js | frameCount Variable
- p5.js | width variable
- p5.js | displayWidth Variable
- PHP | Check if a variable is a function
- HTML| DOM Variable Object
- How to declare a global variable in PHP?
- JavaScript | Set object key by variable
- How to use dynamic variable names in JavaScript ?
- How to check if a variable is an array in JavaScript?
- JavaScript | Check if a variable is a string
- JavaScript | Check the existence of variable
- How to use a variable for a key in a JavaScript object literal?
- Understanding variable scopes in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



