Convert from HSB to RGB

Hi!
Can someone send me a function that converts HSB input into RGB? (color formats, RGB = red, green, blue, HSB = hue, saturation, brightness (or Value if it is HSV))

preferred format:

color toRGB(int h, int s, int b) {
  <calculations> 
  return color(r,g,b);
}

Use pushStyle() & colorMode() before color(). Then finish w/ popStyle():

1 Like

I was making a program like this:

void setup() {
  
}
void draw() {
  background(splitColorV2("RGB:"+(int)random(255)+":"+(int)random(255)+":"+(int)random(255)+":255"));
  noLoop();
}
void mousePressed() {loop();}
color splitColorV2(String input) {
  String parameters[] = split(input,":");
  printArray(parameters);
  String mode = parameters[0];
  int p1 = int(parameters[1]), p2 = int(parameters[2]), p3 = int(parameters[3]),a = ((parameters.length == 5)? int(parameters[4]) : 255);
  println(parameters.length);
  if(mode == "RGB") {
    return color(p1,p2,p3,a);
  } else {
    color convertedColor = toRGB(p1,p2,p3,a);
    return convertedColor;
  }
}
color toRGB(int h, int s, int b, int a) {
  return(color(h,s,b,a));
}
color toRGB(final color h, final color s, final color b) {
  return toRGB(h, s, b, 255);
}

color toRGB(final color h, final color s, final color b, final color a) {
  pushStyle();
  colorMode(HSB, 360, 100, 100, 255);
  final color rgb = color(h, s, b, a);
  popStyle();
  return rgb;
}
1 Like

Some good stuff here:

:)

2 Likes