# Get() returns RGB values while the colorMode is set to HSB

**URL:** <https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827>\
**Category:** Beginners\
**Created:** [July 25, 2020, 2:18am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827 "2020-07-25T02:18:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![papaboo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/papaboo/32/11236_2.png) [@papaboo](https://discourse.processing.org/u/papaboo)\
**Post date:** [July 25, 2020, 2:18am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/1 "2020-07-25T02:18:00Z")

</div>

I’ve swicthed to p5.js from Procesisng.js today (I’ll miss that dude) and already encountered a problem.

get() returns an RGB value but my canvas is set to HSB mode. As far as I remember that wasn’t happening when I was working with Processing.js; it used to return according to the colorMode of the sketch.

Is there a way to convert it?

---

<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:** [July 25, 2020, 2:36am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/2 "2020-07-25T02:36:47Z")

</div>

Hello,

You can use the hue(), saturation() and brightness() functions.

Reference:  
[https://p5js.org/reference/](https://p5js.org/reference/)

`:)`

---

<div class="post-metadata">

**Author:** ![aks9](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aks9](https://discourse.processing.org/u/aks9)\
**Post date:** [August 15, 2020, 8:12am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/3 "2020-08-15T08:12:45Z")

</div>

I’m having the same issue. I don’t understand how to use @glv’s response about using `hue()` etc — as far as I can tell, you have to give either a HSB or HSL array to the `hue()` function, so it can’t work.

I want to keep my program in HSB colorMode. Is there a way for `get()` to return a HSB array, or a way to convert an RGB array to a HSB array?

Thanks for any help

---

<div class="post-metadata">

**Author:** ![jamesb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jamesb/32/10257_2.png) [@jamesb](https://discourse.processing.org/u/jamesb)\
**Post date:** [August 15, 2020, 8:45am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/4 "2020-08-15T08:45:57Z")

</div>

Since HSB is an acronym for Hue, Saturation and Brightness, you can create a wrapper function, for example: `getSketchColor()`.

Within this wrapper function you could fetch the colours in the normal way and assign them respectively to the arguments for the methods that @glv mentioned.

Whenever you want to get the sketch colour you could use your wrapper function instead of the normal.

---

<div class="post-metadata">

**Author:** ![aks9](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aks9](https://discourse.processing.org/u/aks9)\
**Post date:** [August 15, 2020, 9:55am UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/5 "2020-08-15T09:55:18Z")

</div>

Hi James,  
What do you mean by “fetch the colours in the normal way”?  
The only way I know of is by using `get()`, which I can’t combine with the HSB functions. That’s why using the Hue, Saturation, or Brightness won’t work, since they require H or S or B values as their inputs, but `get()` only gives you R, G and B.

I’m not sure how making a wrapper would work unless I had a way to tell that wrapper how to convert from RGB to HSB? Thanks for any clarification

---

<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:** [August 15, 2020, 7:23pm UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/8 "2020-08-15T19:23:41Z")

</div>

> [@aks9](#):
>
> The only way I know of is by using `get()` , which I can’t combine with the HSB functions. That’s why using the Hue, Saturation, or Brightness won’t work, since they require H or S or B values as their inputs, but `get()` only gives you R, G and B.

[https://p5js.org/reference/#/p5/get](https://p5js.org/reference/#/p5/get)

> Returns an array of [R,G,B,A] values for any pixel

```auto
get(x, y)

```

> **[reference | p5.js](https://p5js.org/reference/#/p5/hue)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> Extracts the hue value from a color or **pixel array**.  
> Hue exists in both HSB and HSL. This function will return the HSB-normalized hue when supplied with an HSB color object **(or when supplied with a pixel array while the color mode is HSB)**

I tested this and it works for H and B but did not seem to give correct value for S.

A little exploration lead me to this:  
[https://github.com/processing/p5.js/issues/4667](https://github.com/processing/p5.js/issues/4667)  
[https://github.com/processing/p5.js/issues/1620](https://github.com/processing/p5.js/issues/1620)

The above issues also cross link to other related issues if you care to follow those.

One of the posts said this works correctly:  
[https://bgrins.github.io/TinyColor/](https://bgrins.github.io/TinyColor/)

Additional resources:

> **[home | p5.js](https://p5js.org/)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

See references:

- Color
- Pixels

> **[learn | p5.js](https://p5js.org/learn/)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

See:

- Color

`:)`

---

<div class="post-metadata">

**Author:** ![aks9](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aks9](https://discourse.processing.org/u/aks9)\
**Post date:** [August 16, 2020, 12:08pm UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/9 "2020-08-16T12:08:05Z")

</div>

Hmm, it doesn’t really work for me either. H and B don’t work reliably either for some reason.

Thanks for the link to TinyColor, I installed it and managed to get it working. Needed to do some work to get the TinyColor output to be readable by `fill()` but in the end I got it working.

---

<div class="post-metadata">

**Author:** ![jamesb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jamesb/32/10257_2.png) [@jamesb](https://discourse.processing.org/u/jamesb)\
**Post date:** [August 16, 2020, 1:34pm UTC](https://discourse.processing.org/t/get-returns-rgb-values-while-the-colormode-is-set-to-hsb/22827/10 "2020-08-16T13:34:25Z")

</div>

What I mean by “fetch the colours in the normal way” is by using `get()` - as you have been doing and then use them to perform the conversion. There are methods for converting RGB to HSB values which you then use in the wrapper function I mentioned.
