Try Josh Whizzle's ColorMathUtil.as. It has everything you need, and then some.
Get Color From HSL Values in Flash
-
04-06-2022 - |
Вопрос
I just want to know how to get a Color() Object or a Hex Color Value ( uint ) from HSL values in flash.´
The idea behind the HSL is, that i can map vaues from a range ob anything, to the range of the Hue ( 0 - 360 ) and get the coresponding color.
Further I want to control the Hue value seperate from the "lightness" or "brightness" value. the saturation will allways be 100%.
The "base" of my code looks like this:
function getHSL( var Hue, var Saturation, var Lightness ) {
// Hue = 0 - 360, Satturation = 0 - 100, Lightness = 0 - 100
// DO THE MAGIC
return color // as3 Color() object
}
So if I would have this funktion, i could just call it in a for( i=0; i<360; i++)
loop where i
would be the Hue to create a rainbow color spectrum.
i already have done some map()
functions to easily handle "streching" color spectrums ( like bars that are not exactly 360 px long.
So guys if you have any idea how i could generate Colors from HSL values in as3, please tell me.
SOLUTION UPDATE
function getColorFromHSL( h:Number, s:Number, v:Number ):Array {
var r:Number = 0;
var g:Number = 0;
var b:Number = 0;
var rgb:Array = [];
var tempS:Number = s / 100;
var tempV:Number = v / 100;
var hi:int = Math.floor(h/60) % 6;
var f:Number = h/60 - Math.floor(h/60);
var p:Number = (tempV * (1 - tempS));
var q:Number = (tempV * (1 - f * tempS));
var t:Number = (tempV * (1 - (1 - f) * tempS));
switch(hi)
{
case 0: r = tempV; g = t; b = p; break;
case 1: r = q; g = tempV; b = p; break;
case 2: r = p; g = tempV; b = t; break;
case 3: r = p; g = q; b = tempV; break;
case 4: r = t; g = p; b = tempV; break;
case 5: r = tempV; g = p; b = q; break;
}
rgb = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
return rgb;
}
Решение