This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

background()

Examples
example pic
background(51);
example pic
background(255, 204, 0);
example pic
PImage img;
img = loadImage("laDefense.jpg");
background(img);
Description The background() function sets the color used for the background of the Processing window. The default background is light gray. background() is typically used within the draw() function to clear the display window at the beginning of each frame.

An image can also be used as the background for a sketch, although the image's width and height must match that of the sketch window. To resize an image to the size of the sketch window, use image.resize(width, height).

Images used with background() will ignore the current tint() setting.

It is not possible to use transparency (alpha) with background colors on the main drawing surface; you can acheive the same effect with createGraphics().
Syntax
background(rgb)
background(rgb, alpha)
background(gray)
background(gray, alpha)
background(v1, v2, v3)
background(v1, v2, v3, alpha)
background(image)
Parameters
rgb int: any value of the color datatype
alpha float: opacity of the background
gray float: specifies a value between white and black
v1 float: red or hue value (depending on the current color mode)
v2 float: green or saturation value (depending on the current color mode)
v3 float: blue or brightness value (depending on the current color mode)
image PImage: PImage to set as background (must be same size as the sketch window)
Returnsvoid
Relatedstroke()
fill()
tint()
colorMode()
Updated on February 19, 2013 07:58:55pm EST

Creative Commons License