background()

Description

The background() function sets the color used for the background of the Processing window. The default background is black. Color the whole screen any of 16,777,216 different colors

The value for the parameter “gray” must be less than or equal to 255.

Syntax


background(gray)

or


background(value1, value2, value3)


Parameters

gray – number specifying value between white and black

value1 – red value

value2 – green value

value3 – blue value

Returns

none

Related

stroke()
fill()

Example


void setup()
{
background(0,0,0);// set the screen black
}

void loop()
{
background(255,0,0);// set the screen Red
delay(1000); //delay 1 second

background(0,255,0);// set the screen Green
delay(1000); //delay 1 second

background(0,0,255);// set the screen Blue
delay(1000); //delay 1 second

background(255);// set the screen White
delay(1000); //delay 1 second

background(255,255,255);// set the screen White
delay(1000); //delay 1 second

background(200);// set the screen to a light shade of gray
delay(1000); //delay 1 second

background(200,200,200);// set the screen to a light shade of gray
delay(1000); //delay 1 second

background(150);// set the screen to a lighter shade of gray
delay(1000); //delay 1 second

background(150,150,150);// set the screen to a lighter shade of gray
delay(1000); //delay 1 second

background(100);// set the screen to a much lighter shade of gray
delay(1000); //delay 1 second

background(100,100,100);// set the screen to a much lighter shade of gray
delay(1000); //delay 1 second
}

Notes


background(100)

is the same as


background(100,100,100)


or


background(182)

is the same as


background(182,182,182)




Edit History