p5.js print() function
Last Updated :
10 Aug, 2023
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() {
createCanvas(400, 400);
print( "Hello GeeksForGeeks" );
}
function draw() {
background(220);
}
|
Output:
Example 2: This example uses print() function to display the content on console.
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 4; i++) {
for (let j = 0; j < i; j++) {
print( "*" );
}
print( "\n" );
}
}
function draw() {
background(220);
}
|
Output:
Reference: https://p5js.org/reference/#/p5/print
Share your thoughts in the comments
Please Login to comment...