// RGB to HSB // // Given an RGB set, returns the HSB equivalent // Worked this out for my color search engine // // Written By Sean Hyde-Moyer (Copywrite 1995-2003) // This program is released to the public under the terms of the // GNU GENERAL PUBLIC LICENSE // See http://www.gnu.org/copyleft/gpl.txt // For the full text of the license agreement rgb2hsb: r,g,b { minny = min(r,g); minny = min(minny,b); maxy = max(r,g); maxy = max(maxy,b); diff = maxy - minny; //_____________________________________________Hue_________________ if(maxy == minny){ hue = "Undefined"; } else{ r_dist = (maxy - r)/diff; g_dist = (maxy - g)/diff; b_dist = (maxy - b)/diff; if(r == maxy){ hue = (b_dist - g_dist); } if(g == maxy){ hue = 2 + (r_dist - b_dist); } if(b == maxy){ hue = 4 +(g_dist - r_dist); } hue = (hue * 60); if(hue <= 0){ hue = (hue + 360); } hue = round(hue,0); } if(hue != "Undefined"){ //_____________________________________________Sat_________________ sat = integer(100 * ((maxy - minny) / maxy)); //_____________________________________________Val_________________ val = maxy; //___________________________________________Alternate Brightness brite = round(100 * (val * .0039216),0); } else{ sat = 999; hue = 999; bri = 999; } return(hue,sat,brite); }