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() {
createCanvas(380, 80);
}
function draw() {
background(220);
textSize(16);
textAlign(CENTER);
fill(color( 'Green' ));
text( "Height of Canvas is : "
+ height, 180, 50);
}
|
Output:
Example 2: This example uses height variable to display the height of window.
function setup() {
height = windowHeight;
createCanvas(380, height);
}
function draw() {
background(220);
textSize(16);
textAlign(CENTER);
fill(color( 'Green' ));
text( "Height of Canvas is : " +height, 180, height/2);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/height
Last Updated :
10 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...