p5.js background() function
Last Updated :
11 Aug, 2023
Improve
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:
javascript
Output:
Example 2: This example uses background() function to set the background color.
javascript
Output:
Reference: https://p5js.org/reference/#/p5/background
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
}

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