Loading

PcolorMode


processing
Since v1.0.0
Available on all platforms
See also

Changes the way Processing interprets color data. By default, the parameters for Pfill, Pstroke, Pbackground, and Pcolor are defined by values between 0 and 255 using the RGB color model. The PcolorMode 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.

When using max different from default values, do not work with grayscale.

After changing the range of values for colors with code like colorMode(HSB, 360, 100, 100), those ranges remain in use until they are explicitly changed again. For example, after running colorMode(HSB, 360, 100, 100) and then changing back to colorMode(RGB), the range for R will be 0 to 360 and the range for G and B will be 0 to 100. To avoid this, be explicit about the ranges when changing the color mode. For instance, instead of colorMode(RGB), write colorMode(RGB, 255, 255, 255).

Link to original Processing doc

Signature

Examples

// @preview image //working with RGB [0.0 1.0] 300 200 '2D' PGraphics //new image instance, 300x200 pixels 3 PstrokeWeight //stroke width 3pixels 0xff0000ff Pstroke //blue stroke (ARGB color) 'RGB' 1.0 PcolorMode //change mode and max values 1000.0 1.0 0 Pcolor Pfill //yellow (1000 is clamped to [0 1] range) 10 50 50 100 Prect // do not work with grayscale ! // 0.5 Pcolor Pfill //dark grey (0.5 will be casted to integer...) // 60 50 50 100 Prect // 180 150 Pcolor Pfill //dark grey with 150/255 opacity // 110 50 50 100 Prect 0 1.0 1.0 Pcolor Pfill //cyan (green+blue) 160 50 50 100 Prect 1.0 0 0 0.5 Pcolor Pfill //red with 60/255 opacity 210 50 50 100 Prect Pencode //render the image in a base64 format on the stack