This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Name

colorMode()

Examples
example pic
noStroke();
colorMode(RGB, 100);
for (int i = 0; i < 100; i++) {
  for (int j = 0; j < 100; j++) {
    stroke(i, j, 0);
    point(i, j);
  }
}
example pic
noStroke();
colorMode(HSB, 100);
for (int i = 0; i < 100; i++) {
  for (int j = 0; j < 100; j++) {
    stroke(i, j, 100);
    point(i, j);
  }
}
example pic
// If the color is defined here, it won't be 
// affected by the colorMode() in setup(). 
// Instead, just declare the variable here and 
// assign the value after the colorMode() in setup()
//color bg = color(180, 50, 50);  // No
color bg;  // Yes, but assign it in setup()

void setup() {
  size(100, 100);
  colorMode(HSB, 360, 100, 100);
  bg = color(180, 50, 50);
}

void draw() {
  background(bg);	
}
Description Changes the way Processing interprets color data. By default, the parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using the RGB color model. The colorMode() function is used to change the numerical range used for specifying colors and to switch color systems. For example, calling colorMode(RGB, 1.0) will specify that values are specified between 0 and 1. The limits for defining colors are altered by setting the parameters max, max1, max2, max3, and maxA.
Syntax
colorMode(mode)
colorMode(mode, max)
colorMode(mode, max1, max2, max3)
colorMode(mode, max1, max2, max3, maxA)
Parameters
mode int: Either RGB or HSB, corresponding to Red/Green/Blue and Hue/Saturation/Brightness
max float: range for all color elements
max1 float: range for the red or hue depending on the current color mode
max2 float: range for the green or saturation depending on the current color mode
max3 float: range for the blue or brightness depending on the current color mode
maxA float: range for the alpha
Returnsvoid
Relatedbackground()
fill()
stroke()
Updated on May 19, 2014 05:30:02pm PDT

Creative Commons License