Colours in Processing

Other topics

Remarks:

Although it has not been mentioned in the official Processing documentation, there is a CMYK mode which you can use.

Colour Notation

There are various ways to use colours in Processing since Processing is very flexible with colour formats.

RGB and RGBA

This is the standard RGB(A) notation and the default color mode. The first three colour values (red, green, blue) range from 0 to 255. For example, the below example is the colour red since red is maxed out at 255 while the others colours are at 0. White is at (255, 255, 255) and black is (0, 0, 0). The optional 4th parameter indicates the alpha value -- i.e. transparency. As in other the components, the range of values is again [0-255]; 0 being completely transparent and 255 being completely solid.

color(255, 0, 0) // This is red

color(0, 255, 0, 255) // This is opaque green, and is the same as color(0, 255, 0)

color(255, 255, 0, 10) // This is almost transparent yellow

HSB

HSB notation is similar to RGB notation, except for the fact that red, green, and blue are replaced with hue, saturation, and brightness, respectively. You can switch into HSB by using colorMode(HSB).

color(0, 0, 255) //This is white

As with RGB, HSB also has the alpha value as the fourth parameter.

Gray Values

If one parameter is specified to a color function, it will be interpreted as the amount between black and white. White is represented as 255, and black as 0. It is the same as color(param1, param1, param1) in RGB mode. If two parameters are specified, then the first parameter will be interpreted as above and the second will be the alpha value.

Syntax:

  • color(r, g, b);
  • color(r, g, b, alpha);
  • color(gray);
  • color(gray, alpha);
  • color(h, s, l); //The mode must be HSB. You can change this using colorMode.

Parameters:

ParametersDetails
rIs the red of the color when the mode is RGB.
gIs the green of the color when the mode is RGB.
bIs the blue of the color when the mode is RGB.
alphaIs the opacity of the color.
hThe hue of the color when the mode is HSB.
sThe saturation of the color when the mode is HSB.
lThe brightness/lightness of the color when the mode is HSB.
grayThe value between black (being 0) and white (being 255).

Contributors

Topic Id: 8283

Example Ids: 26583

This site is not affiliated with any of the contributors.