# Convert from HSB to RGB

**URL:** https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672
**Category:** Beginners
**Created:** [January 1, 2021, 5:32pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672 "2021-01-01T17:32:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [January 1, 2021, 5:32pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672/1 "2021-01-01T17:32:42Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 1, 2021, 5:37pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672/2 "2021-01-01T17:37:21Z")

</div>

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

> **[pushStyle() \\ Language (API) \\ Processing 3+](https://Processing.org/reference/pushStyle_.html)**

> **[colorMode() \\ Language (API) \\ Processing 3+](https://Processing.org/reference/colorMode_.html)**

> **[popStyle() \\ Language (API) \\ Processing 3+](https://Processing.org/reference/popStyle_.html)**

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [January 1, 2021, 5:56pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672/3 "2021-01-01T17:56:56Z")

</div>

I was making a program like this:

```auto
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));
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 1, 2021, 6:11pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672/4 "2021-01-01T18:11:33Z")

</div>

```java
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;
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [January 1, 2021, 7:40pm UTC](https://discourse.processing.org/t/convert-from-hsb-to-rgb/26672/5 "2021-01-01T19:40:48Z")

</div>

Some good stuff here:

> **[Color Gradients in Processing (v 2.0)](https://behreajj.medium.com/color-gradients-in-processing-v-2-0-e5c0b87cdfd2)**
>
> This tutorial on color gradients is an overhaul of a prior version; hopefully it will prove more useful to creative coders who wish to work…

`:)`
