home/ atoms/ p5js-color-specification-modes

p5.js accepts colors as a grayscale number, an RGB triple, or a CSS color-name string

p5.js color functions (fill, stroke, background) accept several formats: a single number for grayscale; three numbers separated by commas for red, green, blue; or a string with an HTML color name (or a hex value). The colorMode() function can switch interpretation to HSB, often more intuitive for creative coding since you can sweep hue while holding saturation and brightness fixed — ideal for cycling through rainbow hues. Mixing a name string and numbers in the same call is not valid.

Examples

background(220); // grey fill(135, 206, 235); // sky blue RGB fill(‘yellow’); // CSS name colorMode(HSB, 360, 100, 100); fill(200, 80, 90); // HSB

Assessment

Name the three main color formats p5.js accepts. Explain when you would choose HSB over RGB for an animation that cycles through rainbow hues.

“1 number for gray-scale color; 3 numbers separated by commas for”