Open In App

p5.js displayHeight Variable

Last Updated : 10 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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



Previous Article
Next Article

Similar Reads

variable === undefined vs. typeof variable === “undefined” in JavaScript
Undefined comes into the picture when any variable is defined already but not has been assigned any value. Undefined is not a keyword. A function can also be undefined when it doesn't have the value returned. There are two ways to determine if a variable is not defined, Value and type. var geeks; alert ( geeks === undefined) It's so clear that you
2 min read
Understanding variable scopes in JavaScript
In JavaScript, there are two types of variable scopes: Global Scope: Variables declared Globally (outside of any function) have Global Scope and Global variables can be accessed from anywhere in a program. Similar to function scope variables declared with var, let and const are quite similar when declared outside a block.Scope outside the outermost
6 min read
What is the use of underscore variable in REPL ?
In the previous Node.js REPL post, we've discussed what is Node.js REPL and how to use it on your command prompt. We've also discussed how to perform arithmetical operations, how to use node library functions, and how to use loops in REPL. In this article, we're going to discuss what is the use of the underscore (_) variable in Node.JS REPL. Unders
2 min read
How to call PHP function from string stored in a Variable
Given the names of some user-defined functions stored as strings in variables. The task is to call the functions using the names stored in the variables. Example: <?php // Function without argument function func() { echo "geek"; } // Function with argument function fun($msg) { echo $msg; } // Call func and fun using $var and $var1 $var
2 min read
HTML| DOM Variable Object
The DOM Variable Object is used to represent HTML <var> element. The var element is accessed by getElementById(). Syntax: var element = document.getElementById("ID"); Where “id” is the ID assigned to the “var” tag. Example-1: C/C++ Code <!DOCTYPE html> <html> <head> <title>HTML| DOM Vari
2 min read
Variable Shadowing in JavaScript
Block Scoping: To understand shadowing in JavaScript, we need to be clear with the scope first. In computer programming languages, Scope is a certain section/region of the program where a defined variable can have its existence and can be recognized, beyond that it can't be accessed. In JavaScript, a Block is a compound statement that is defined by
2 min read
PHP | Check if a variable is a function
To determine whether a passed argument is a function or not, Few of the most preferred methods are shown below. Using is_callable() Function: It is an inbuilt function in PHP which is used to verify the contents of a variable in called as a function. It can check that a simple variable contains the name of a valid function, or that an array contain
3 min read
JavaScript Check the existence of variable
JavaScript has a built-in function to check whether a variable is defined/initialized or undefined. To do this, we will use the typeof operator. The typeof operator will return undefined if the variable is not initialized and the operator will return null if the variable is left blank intentionally.Note: The typeof operator will check whether a var
2 min read
How to check a variable is of function type using JavaScript ?
A function in JavaScript is the set of statements used to perform a specific task. A function can be either a named one or an anonymous one. The set of statements inside a function is executed when the function is invoked or called. A function can be assigned to a variable or passed to a method. var gfg = function(){/* A set of statements */}; Here
3 min read
p5.js | frameCount Variable
The frameCount variable in p5.js is used to hold the number of frames which are displayed since the program started. Inside setup() function the value is 0, after the first iteration of draw it is 1, etc. Syntax: frameCount Below program illustrates the frameCount Variable in p5.js: Example: This example uses frameCount variable to display the fram
1 min read