[−][src]Static p5_sys::global::colorMode
pub static colorMode: ColorModeInternalType
colorMode() changes the way p5.js 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. This is equivalent to setting colorMode(RGB, 255). Setting colorMode(HSB) lets you use the HSB system instead. By default, this is colorMode(HSB, 360, 100, 100, 1). You can also use HSL.
Note: existing color objects remember the mode that they were created in, so you can change modes as you like without affecting their appearance.
Examples
noStroke(); colorMode(RGB, 100); for (let i = 0; i < 100; i++) { for (let j = 0; j < 100; j++) { stroke(i, j, 0); point(i, j); } }
noStroke(); colorMode(HSB, 100); for (let i = 0; i < 100; i++) { for (let j = 0; j < 100; j++) { stroke(i, j, 100); point(i, j); } }
colorMode(RGB, 255); let c = color(127, 255, 0); colorMode(RGB, 1); let myColor = c._getRed(); text(myColor, 10, 10, 80, 80);
noFill(); colorMode(RGB, 255, 255, 255, 1); background(255); strokeWeight(4); stroke(255, 0, 10, 0.3); ellipse(40, 40, 50, 50); ellipse(50, 50, 40, 40);
Overloads
mode
either RGB, HSB or HSL, corresponding to
Red/Green/Blue and Hue/Saturation/Brightness
(or Lightness)
max?
range for all values
mode
either RGB, HSB or HSL, corresponding to
Red/Green/Blue and Hue/Saturation/Brightness
(or Lightness)
max1
range for the red or hue depending on the
current color mode
max2
range for the green or saturation depending
on the current color mode
max3
range for the blue or brightness/lightness
depending on the current color mode
maxA?
range for the alpha