HSL / HSV to RGB colors


#1

just adapted for now this little fonction picked from web to return a color via HSLA input parameters
(hue, sat, lum, alpha) in 0…1 range rather than RGB in dashboard witch if personally find more intuitive,
(in fact its more HSV than HSL but…) that allow ie quickly spread rainbows, or randomize/roll hue rolors,
hilight an off to on color ect…

probably more cpu intense, but blocks seems to handle it without problems :slight_smile:
wonder if hard coded might be better optimized function could be implemented in future updates,
just a thought, or maybe some can still find it usefull as is…
nb: a switch/case would def be useful, but think ya know that already^^
anyway… having lot of fun with dashboard, thanks for amazing job! love it

//==============================================================

int HSLA(float h, float s, float l, float a) //returns ARGB color from HSLA 0…1
{
float r;
float g;
float b;

h = h*360;

if (h < 0) h = 0;
if (h > 359) h = 359;
if (s < 0) s = 0;
if (s > 1) s = 100;
if (l < 0) l = 0;
if (l > 1) l = 100;

float tmp = h/60.0;

int hi = int(tmp); //floor

float f = tmp - hi;

float p = l * (1 - s);
float q = l * (1 - f * s);
float t = l * (1 - (1 - f) * s);

  if(hi ==0)
{
  	r = l;
  	g = t;
  	b = p;
}

else if(hi ==1)
{
r = q;
g = l;
b = p;
}
else if(hi ==2)
{
r = p;
g = l;
b = t;
}

else if(hi ==3)
{
r = p;
g = q;
b = l;
}
else if(hi ==4)
{
r = t;
g = p;
b = l;
}

else if(hi ==5)
{
r = l;
g = p;
b = q;
}

return makeARGB(int(a*255),int(r*255),int(g*255),int(b*255));

}
//////////////////////////////////////