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:

"rgba(255,255,255,1)
levels c1: 255,255,255,255 
rgba(0,0,0,1)
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);
  colorMode(HSB,360,100,100)
}

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)
  noLoop()
}

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

1 Like