I’m trying to convert HSB values to RGB values using this algorithm, but I am not getting correct values. I have a fixed s of 29, a fixed b of 100, and am generating random integers between 0-360 for the h value, and feeding them into the function to get RGB back:

float h = (arc4random() % 360);
float s = 29;
float b = 100;
HSL2RGB(h, s, b, &red, &green, &blue);
NSLog(@"r:%f g:%f b:%f", red, green, blue);
output:
r:2971.000000 g:2971.000000 b:2971.000000
I tried this too:
float h = (arc4random() % 360)/1000.0;
float s = 0.29;
float b = 1.0;
HSL2RGB(h, s, b, &red, &green, &blue);
NSLog(@"r:%f g:%f b:%f", red, green, blue);
output:
r:1.000000 g:1.000000 b:1.000000
Am I doing something wrong, or is this algorithm messed up?
I don’t know your algorithm but I should you to use this algorigthm:
I used it into own of my project and I had no problem with it. 🙂