Reference colorMode()

colorMode()

Changes the way color values are interpreted.

By default, the Number parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using the RGB color model. This is equivalent to calling colorMode(RGB, 255). Pure red is color(255, 0, 0) in this model.

Calling colorMode(RGB, 100) sets colors to use RGB color values between 0 and 100. Pure red is color(100, 0, 0) in this model.

Calling colorMode(HSB) or colorMode(HSL) changes to HSB or HSL system instead of RGB. Pure red is color(0, 100, 100) in HSB and color(0, 100, 50) in HSL.

p5.Color objects remember the mode that they were created in. Changing modes doesn't affect their appearance.

Examples

Syntax

colorMode(mode, [max])
colorMode(mode, max1, max2, max3, [maxA])

Parameters

mode
Constant:

either RGB, HSB or HSL, corresponding to Red/Green/Blue and Hue/Saturation/Brightness (or Lightness).

max
Number:

range for all values.

max1
Number:

range for the red or hue depending on the current color mode.

max2
Number:

range for the green or saturation depending on the current color mode.

max3
Number:

range for the blue or brightness/lightness depending on the current color mode.

maxA
Number:

range for the alpha.

Notice any errors or typos? Please let us know. Please feel free to edit src/color/setting.js and open a pull request!

Related References