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.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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);
}

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.