ActionScript 3 AS3 HSB颜色(对象)到RGB颜色(对象)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3 HSB颜色(对象)到RGB颜色(对象)相关的知识,希望对你有一定的参考价值。
var darkGreenHsbObj:Object = new Object();
darkGreenHsbObj.h = 90;
darkGreenHsbObj.s = 100;
darkGreenHsbObj.b = 40;
var darkGreenRgbObj:Object = HSBtoRGB(darkGreenHsbObj.h, darkGreenHsbObj.s, darkGreenHsbObj.b);
trace("HSB: " + darkGreenHsbObj.h + ", " + darkGreenHsbObj.s + ", " + darkGreenHsbObj.b);
trace("RGB: " + darkGreenRgbObj.r + ", " + darkGreenRgbObj.g + ", " + darkGreenRgbObj.b);
function HSBtoRGB(h:int, s:int, b:int):Object
{
var rgb:Object = new Object();
var max:Number = (b * 0.01) * 255;
var min:Number = max * (1 - (s * 0.01));
if (h == 360) {
h = 0;
}
if (s == 0) {
rgb.r = rgb.g = rgb.b = b*(255*0.01) ;
} else {
var _h:Number = Math.floor(h / 60);
switch(_h){
case 0:
rgb.r = max ;
rgb.g = min+h * (max-min)/ 60;
rgb.b = min;
break;
case 1:
rgb.r = max-(h-60) * (max-min)/60;
rgb.g = max;
rgb.b = min;
break;
case 2:
rgb.r = min ;
rgb.g = max;
rgb.b = min+(h-120) * (max-min)/60;
break;
case 3:
rgb.r = min;
rgb.g = max-(h-180) * (max-min)/60;
rgb.b =max;
break;
case 4:
rgb.r = min+(h-240) * (max-min)/60;
rgb.g = min;
rgb.b = max;
break;
case 5:
rgb.r = max;
rgb.g = min;
rgb.b = max-(h-300) * (max-min)/60;
break;
case 6:
rgb.r = max;
rgb.g = min+h * (max-min)/ 60;
rgb.b = min;
break;
}
rgb.r = Math.min(255, Math.max(0, Math.round(rgb.r)))
rgb.g = Math.min(255, Math.max(0, Math.round(rgb.g)))
rgb.b = Math.min(255, Math.max(0, Math.round(rgb.b)))
}
return rgb;
}
// OUTPUT
// HSB: 90, 100, 40
// RGB: 51, 102, 0
以上是关于ActionScript 3 AS3 HSB颜色(对象)到RGB颜色(对象)的主要内容,如果未能解决你的问题,请参考以下文章
AS3 HSB颜色(对象)到RGB颜色(对象)
AS3 RGB颜色(对象)到HSB颜色(对象)
ActionScript 3 AS3随机颜色
ActionScript 3 AS3:插值颜色
ActionScript 3 AS3获取图像的平均颜色
ActionScript 3 AS3 RGB颜色到十六进制颜色(uint)