Skip to content
Related Articles

Related Articles

p5.js | background() function
  • Last Updated : 09 Apr, 2019

The background() function in p5.js is used to set the color used for the background of the p5.js canvas. The default background is transparent. The color accepted by this function can be of the RGB, HSB, or HSL color depending on the current colorMode.

Syntax:

background(c)

Parameters: This function accepts single parameter c which stores the p5.Color object, color components, or CSS color.

Below programs illustrate the background() function in p5.js:

Example 1: This example uses background() function to set the background color.






function setup() {
      
    // Create Canvas of size 300*300
    createCanvas(300, 300);
}
  
function draw() {
    background(220, 141, 155); //RGB Value
}

Output:

Example 2: This example uses background() function to set the background color.




function setup() {
      
    // Create Canvas of size 300*300
    createCanvas(300, 300);
}
  
function draw() {
      
    // Set background color to green
    background('green');
}

Output:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :