setHsb: wrap fails at 298

ofColor color = ofColor(0);
color.setHsb(297, 255, 255);

prints 42

ofColor color = ofColor(0);
color.setHsb(298, 255, 255);

prints 0

everything > 298 seems to set hue to 0

any reason for this?

thank you!

from setHsb ref:
“A hue value to set in the range of 0 - limit().”

I guess the limit for int is 255. You could use floats too.

You probably already know this but if you want the hue value to wrap around back to zero once it’s over 255 you can use the modulus operator (%) :

color.setHsb(hue%255, 255, 255);

where hue is an integer.

But yeah it would be good if setHsb did this automatically.

This works like that cause ofColor is 8bits so trying to pass an angle between 0…360 would loose resolution. the first parameter is an angle represented in the range 0…255 so 0 is 0 degrees and 255 is 360 degrees so if what you need is to pass an angle between 0…360 you can do

color.setHsb(ofMap(hue, 0, 360, 0, 255), 255, 255);

@Jordi @seb_ly thanks. @seb_ly, yeah, thats prob the most straightforward solution to make it work.

@arturo, I’m curious what happens between 297 and 298 that would make it set to 0 and stay there after (and not 1.0, for that matter). Does color run out of space?

at 297, I get this reading for color:


at 298 and greater, r=0, g=0, b=0 and stay 0.

thanks for your solution-- its a cool idea for some other stuff ^.^