Ko zna gde mi su formule, evo malo koda, to je AS, lako je prepraviti u JS
Kôd:
mcPanel.rgb2hsb = function () : Void
{
// sets h, s and b values based on r, g and b
var min : Number = Math.min (Math.min (this.rgb.r, this.rgb.g), this.rgb.b);
var max : Number = Math.max (Math.max (this.rgb.r, this.rgb.g), this.rgb.b);
var delta : Number = max - min;
if (delta == 0)
{
this.hsb.h = 360;
this.hsb.s = 0;
this.hsb.b = max / 255 * 100;
}
else
{
if (this.rgb.r == max) this.hsb.h = (this.rgb.g - this.rgb.b) / delta;
else if (this.rgb.g == max) this.hsb.h = 2 + (this.rgb.b - this.rgb.r) / delta;
else this.hsb.h = 4 + (this.rgb.r - this.rgb.g) / delta;
this.hsb.h *= 60;
this.hsb.h += 360;
this.hsb.h %= 360;
this.hsb.s = (1 - min / max) * 100;
this.hsb.b = max / 255 * 100;
}
}
mcPanel.hsb2rgb = function () : Void
{
// sets r, g and b value on h, s and b info
var max : Number = this.hsb.b * 255 / 100;
var min : Number = (1 - this.hsb.s / 100) * max;
this.hsb.h %= 360;
var f : Number;
if (this.hsb.h < 60) f = this.hsb.h;
else if (this.hsb.h < 180) f = this.hsb.h - 120;
else if (this.hsb.h < 300) f = this.hsb.h - 240;
else f = this.hsb.h - 360;
var mid : Number = min + Math.abs (f / 60) * (max - min);
max = Math.round (max);
mid = Math.round (mid);
min = Math.round (min);
switch (Math.floor (this.hsb.h / 60))
{
case 0:
this.rgb.r = max;
this.rgb.g = mid;
this.rgb.b = min;
break;
case 1:
this.rgb.r = mid;
this.rgb.g = max;
this.rgb.b = min;
break;
case 2:
this.rgb.r = min;
this.rgb.g = max;
this.rgb.b = mid;
break;
case 3:
this.rgb.r = min;
this.rgb.g = mid;
this.rgb.b = max;
break;
case 4:
this.rgb.r = mid;
this.rgb.g = min;
this.rgb.b = max;
break;
case 5:
this.rgb.r = max;
this.rgb.g = min;
this.rgb.b = mid;
break;
}
}