p5.js | background() function
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
Recommended Posts:
- Difference between background and background-color
- CSS | Background
- CSS | background-image Property
- CSS | background-position Property
- CSS | background-clip Property
- How to set multiple background images using CSS?
- CSS | background-color Property
- CSS | background-repeat Property
- CSS | background-size Property
- CSS | background-attachment Property
- CSS | background-origin property
- Set the size of background image using CSS ?
- CSS | background-blend-mode Property
- Set the opacity only to background color not on the text in CSS
- How to stretch and scale background image using CSS?
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.



