Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptp5.js print() function

p5.js print() function

The print() function in p5.js writes the content on console area of the web browser. It is helpful for looking at the data a program is producing which helps in debugging the code. The elements can be separated by using quotes (ā€œā€) and joined with the addition operator (+). Use print(ā€˜\nā€™) to display blank line.

Syntax:

print(c)

Parameters: The function accepts single parameter c which stores the any combination of Number, String, Object, Boolean, Array to print.

Below program illustrates the print() function in p5.js:

Example 1: This example uses print() function to display the content on console.




function setup() {
Ā Ā 
Ā Ā Ā Ā // Create canvas of given size
Ā Ā Ā Ā createCanvas(400, 400);
Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā // print function call
Ā Ā Ā Ā print("Hello GeeksForGeeks");
}
Ā Ā 
function draw() {
Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā // Set the background color
Ā Ā Ā Ā background(220);
}


Output:

Example 2: This example uses print() function to display the content on console.




function setup() {
Ā Ā 
Ā Ā Ā Ā // Create canvas of given size
Ā Ā Ā Ā createCanvas(400, 400);
Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā // print function call
Ā Ā Ā Ā for(let i = 0; i < 4; i++) {
Ā Ā Ā Ā Ā Ā Ā Ā for(let j = 0; j < i; j++) {
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā print("*");
Ā Ā Ā Ā Ā Ā Ā Ā }
Ā Ā Ā Ā Ā Ā Ā Ā print("\n");
Ā Ā Ā Ā }
}
Ā Ā 
function draw() {
Ā Ā Ā Ā Ā Ā 
Ā Ā Ā Ā // Set the background color
Ā Ā Ā Ā background(220);
}


Output:

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

RELATED ARTICLES

Most Popular

Recent Comments

ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
źøˆģ²œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
źµ¬ģ›”ė™ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ˜¤ģ‚°ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ź“‘ėŖ…ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ•ˆģ–‘ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė™ķƒ„ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ģ„œģšøģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶„ė‹¹ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ė¶€ģ²œģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ź³”ė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź°•ģ„œźµ¬ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ź³ ģ–‘ģ¶œģž„ģ•ˆė§ˆ on How to store XML data into a MySQL database using Python?
ķ™”ģ„±ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?
ģ²œķ˜øė™ģ¶œģž„ė§ˆģ‚¬ģ§€ on How to store XML data into a MySQL database using Python?