[−][src]Static p5_sys::global::background
pub static background: BackgroundInternalType
The background() function sets the color used for the background of the p5.js canvas. The default background is transparent. This function is typically used within draw() to clear the display window at the beginning of each frame, but it can be used inside setup() to set the background on the first frame of animation or if the background need only be set once.
The color is either specified in terms of the RGB, HSB, or HSL color depending
on the current colorMode. (The default color space
is RGB, with each value in the range from 0 to 255). The alpha range by default
is also 0 to 255.
If a single string argument is provided, RGB, RGBA and Hex CSS color strings and all named color strings are supported. In this case, an alpha number value as a second argument is not supported, the RGBA form should be used.
A p5.Color object can also be provided to set the background color.
A p5.Image can also be provided to set the background image.
Examples
// Grayscale integer value background(51);
// R, G & B integer values background(255, 204, 0);
// H, S & B integer values colorMode(HSB); background(255, 204, 100);
// Named SVG/CSS color string background('red');
// three-digit hexadecimal RGB notation background('#fae');
// six-digit hexadecimal RGB notation background('#222222');
// integer RGB notation
background('rgb(0,255,0)');
// integer RGBA notation
background('rgba(0,255,0, 0.25)');
// percentage RGB notation
background('rgb(100%,0%,10%)');
// percentage RGBA notation
background('rgba(100%,0%,100%,0.5)');
// p5 Color object background(color(0, 0, 255));
Overloads
color
any value created by the color() function
colorstring
color string, possible formats include: integer
rgb() or rgba(), percentage rgb() or rgba(),
3-digit hex, 6-digit hex
a?
opacity of the background relative to current
color range (default is 0-255)
gray
specifies a value between white and black
a?
opacity of the background relative to current
color range (default is 0-255)
v1
red or hue value (depending on the current color
mode)
v2
green or saturation value (depending on the current
color mode)
v3
blue or brightness value (depending on the current
color mode)
a?
opacity of the background relative to current
color range (default is 0-255)
values
an array containing the red, green, blue
and alpha components of the color
image
image created with loadImage() or createImage(),
to set as background
(must be same size as the sketch window)
a?
opacity of the background relative to current
color range (default is 0-255)