figure I show how to convert RGB to HSL to RGB
PHP Code:
function HSL2RGB( temp.hue, temp.sat, temp.lum)
{
temp.chroma = ( 1 - abs( 2 * temp.lum - 1)) * temp.sat;
temp.hue = temp.hue / 60;
temp.xVal = temp.chroma * ( 1 - abs(( temp.hue % 2) - 1));
temp.r = temp.hue == 0? 0: temp.hue < 1? temp.chroma: temp.hue < 2? temp.xVal: temp.hue < 3? 0: temp.hue < 4? 0: temp.hue < 5? temp.xVal: temp.chroma;
temp.g = temp.hue == 0? 0: temp.hue < 1? temp.xVal: temp.hue < 2? temp.chroma: temp.hue < 3? temp.chroma: temp.hue < 4? temp.xVal: temp.hue < 5? 0: 0;
temp.b = temp.hue == 0? 0: temp.hue < 1? 0: temp.hue < 2? 0: temp.hue < 3? temp.xVal: temp.hue < 4? temp.chroma: temp.hue < 5? temp.chroma: temp.xVal;
temp.m = temp.lum - 0.5 * temp.chroma;
return { temp.r + temp.m, temp.g + temp.m, temp.b + temp.m};
}
function RGB2HSL( temp.r, temp.g, temp.b)
{
temp.max = max( max( temp.r, temp.g), temp.b);
temp.min = min( min( temp.r, temp.g), temp.b);
temp.chroma = temp.max - temp.min;
temp.a = (( 2 * temp.r) - temp.g - temp.b) / 2;
temp.b = (( 3 ^ 0.5) / 2) * ( temp.g - temp.b);
temp.hue = arctan( temp.b / temp.a);
temp.lum = 0.5 * ( temp.max + temp.min);
temp.sat = temp.chroma == 0? 0: ( temp.chroma / ( 1 - abs( 2 * temp.lum - 1)));
return { int( radToDeg( temp.hue) % 360), temp.sat, temp.lum};
}
and now an example to find the Inverted color of an HSL color
lets say we want to find the inverted RGB color with red's HSL
PHP Code:
function onCreated()
{
temp.red = { 0, 1, 0.5}; //Red's HSL
temp.inv = HSL2RGB(( temp.red[ 0] - 180) % 360, temp.red[ 1], temp.red[ 2]);
echo( temp.inv);
}
which you get { 0, 1, 1} which is Cyan's RGB