I have a small script that generates the web safe colors (both the 216 safe colors and the CSS/X11 named colors), and I want the option to sort by Hue, Saturation, or Brightness (or value... HSB vs HSV color). I have converted the colors into HSV, and I can sort by H (Has to be done in the order: Hue, Sat, Brightness), but not S and V/B... I have looked at charts, and though my sorts come CLOSE, they dont match up 100%. Here is my sort code (I am using a UASORT() to a user defined sort function)
function SortHexColor_H($a,$b)
{
$t=BreakUpHexColor($a);
$s=BreakUpHexColor($b);
$t=RGBtoHSV($t[0],$t[1],$t[2]);
$s=RGBtoHSV($s[0],$s[1],$s[2]);
if ($t[0]!=$s[0])
return ($t[0] > $s[0]) ? -1 : 1;
if ($t[1]!=$s[1])
return ($t[1] > $s[1]) ? -1 : 1;
if ($t[2]!=$s[2])
return ($t[2] > $s[2]) ? -1 : 1;
return 0;
}
the differences in the S and B functions is that the order of the 3 comparisions have to be changed, and even some > comparions have to be changed to <. Anyone got any pointers that they could show me?