//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com //*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt //*** Reuse or modification is free provided you abide by the terms of that license. //*** (Including the first two lines above in your source code satisfies the conditions.) function RGB2HSV(r,g,b){ //***Returns an hsv object from RGB values //***The r (red), g (green), and b (blue) should be values in the range 0 to 1 //***The returned object has .h, .s, and .v properties. //***h is a value from 0 to 360 //***s and v are values between 0 and 1 var h,s,v,max,min,d; r=r>1?1:r<0?0:r; g=g>1?1:g<0?0:g; b=b>1?1:b<0?0:b; max=min=r; if (g>max) max=g; if (gmax) max=b; if (b0)?d/max:0; if (s==0) h=0; else { h=60*((r==max)?(g-b)/d:((g==max)?2+(b-r)/d:4+(r-g)/d)); if (h<0) h+=360; } return {h:h,s:s,v:v} } function HSV2RGB(h,s,v){ //***Returns an rgb object from HSV values //***h (hue) should be a value from 0 to 360 //***s (saturation) and v (value) should be a value between 0 and 1 //***The .r, .g, and .b properties of the returned object are all in the range 0 to 1 var r,g,b,i,f,p,q,t; while (h<0) h+=360; h%=360; s=s>1?1:s<0?0:s; v=v>1?1:v<0?0:v; if (s==0) r=g=b=v; else { h/=60; f=h-(i=Math.floor(h)); p=v*(1-s); q=v*(1-s*f); t=v*(1-s*(1-f)); switch (i) { case 0:r=v; g=t; b=p; break; case 1:r=q; g=v; b=p; break; case 2:r=p; g=v; b=t; break; case 3:r=p; g=q; b=v; break; case 4:r=t; g=p; b=v; break; case 5:r=v; g=p; b=q; break; } } return {r:r,g:g,b:b}; } function Hex2Dec(hex){ //*** Turns a hexadecimal number into an integer return parseInt(hex,16); } function Dec2Hex(dec,padTo){ //*** Turns a decimal number into hexadecimal //*** If padTo is specified (optional) the result is padded with leading zeros to the specified number of characters var h=Math.round(dec).toString(16).toLowerCase(); if (padTo && h.length