p5.js colorMode() Function
The colorMode() function is an inbuilt function in p5.js which is used to let the user choose between RGB or HSB color options. The RGB color mode is by default. Thus, the parameters that which the user passes into it corresponds to red, green and blue values. The user creates various colors by passing in numbers (parameters which ranger between 0 to 255) for these values, therefore, the resulting color is a blend of red, green, and blue. There is another color mode called HSB that uses hue, saturation and brightness values for defining the color.
colorMode(mode, [value]) colorMode(mode, value1, value2, value3, [valueA])
- mode: It is the mode of the color that has to bet set. This can be set to RGB or HSB. It is the equivalent to Red/Green/Blue or Hue/Saturation/Brightness.
- value: It is a number that denotes the range for all values between 0 to 255. It is an optional value.
- value1: It is a number that denotes the range for the red or hue value.
- value2: It is a number that denotes the range for the green or saturation value depending on the current color mode.
- value3: It is a number that denotes the range for the range for the blue or brightness/lightness values depending on the current color mode
- valueA: It is a number that denotes the range for the alpha value, It is between 0 and 255. It is an optional value.
Below programs illustrates the colorMode() function in p5.js: