Once a graphics object has been created, you can access its color as follows:

Function Description
object.setColor(color) Changes the object color to the specified color (e.g. Color.BLACK or Color(255, 0, 255), using specific RGB values).  If the color parameter is omitted, a color selection dialog box will be presented.
object.getColor() Returns the current object color.


ColorGradient function

The colorGradient function returns a list of RGB colors creating a “smooth” gradient between two colors. It may be used in conjunction with code that gives different GUI elements (such as points or circles), different colors to simulate a gradient.  This may be useful in various interactive applications and installations.

Function Description
colorGradient(color1, color2, steps) Returns a list of RGB colors creating a “smooth” gradient between color1 and color2. The number of steps equals the number of colors in the list returned. The result includes color1 but not color2 to allow for composite gradients.

For example, the following creates a gradient list of 12 colors:

Notice how the above excludes the final color (i.e., [251, 147, 14]). This allows to create composite gradients (without duplication of colors). For example, the following:

creates a list of gradient colors from black to orange, and from orange to white. Notice how the final color, white, has to be included separately (using list concatenation). Thus, the result contains a total of 25 unique gradient colors.

Note: For convenience, colorGradient() also works with java.awt.Color parameters, in which case it returns a list of java.awt.Color colors.