Color Variables (Homage to Albers).

Color Variables (Homage to Albers).

This example creates variables for colors that may be referred to in the program by a name, rather than a number.


size(640, 360);
noStroke();
background(51, 0, 0);

color inside = color(204, 102, 0);
color middle = color(204, 153, 0);
color outside = color(153, 51, 0);

// These statements are equivalent to the statements above.
// Programmers may use the format they prefer.
//color inside = #CC6600;
//color middle = #CC9900;
//color outside = #993300;

pushMatrix();
translate(80, 80);
fill(outside);
rect(0, 0, 200, 200);
fill(middle);
rect(40, 60, 120, 120);
fill(inside);
rect(60, 90, 80, 80);
popMatrix();

pushMatrix();
translate(360, 80);
fill(inside);
rect(0, 0, 200, 200);
fill(outside);
rect(40, 60, 120, 120);
fill(middle);
rect(60, 90, 80, 80);
popMatrix();

Functions Used

fill()

Sets the color used to fill shapes

Learn More
size()

Defines the dimension of the display window width and height in units of pixels

Learn More
pushMatrix()

Pushes the current transformation matrix onto the matrix stack

Learn More
rect()

Draws a rectangle to the screen

Learn More
popMatrix()

Pops the current transformation matrix off the matrix stack

Learn More
color()

Creates colors for storing in variables of the color datatype

Learn More
translate()

Specifies an amount to displace objects within the display window

Learn More
noStroke()

Disables drawing the stroke (outline)

Learn More
background()

The background() function sets the color used for the background of the Processing window

Learn More