processing Colours in Processing Colour Notation


Example

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.