Question About color() function and colorMode()

The color() function does not seem to work as I would have assumed. When executing the code below I get the following output:

levels c1: 255,255,255,255 
levels c1: 0,0,0,255 "

I would expect the output to:

  1. Be the same for both print calls 
  2. Be the actual HSB color I put in the color() function, i.e (141,0,0), a dark red.

What gives?

Link to sketch

same code below

function setup() {
  createCanvas(400, 400);

function draw() {
  c1 = color('hsb(141,0,0)')
  c2 = color(141,0,0)
  print(c1 + "\nlevels c1: " + c1.levels)
  print(c2 + "\nlevels c1: " + c2.levels)

A p5.Color object is always an RGBa value.
Current colorMode() is converted to its corresponding RGBa representation.

1 Like