Thursday, September 4, 2025
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

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS