A fast trick to lighten/darken colors
as3, brightness, color
Sep 09code2 Comments
/**
* Scales r-g-b channels by 'scale' factor, having the r-g-b proportions saved
* @param color:uint color to be scaled (i.e. lighten or darken)
* @param scale:Number the scale factor (values -1 to 1) -1 = absolute dark; 1 = absolute light;
* @return uint scaled color
*/
function scaleColor(color:uint, scale:Number):uint
{
var r:int = (color & 0xFF0000) >> 16;
var g:int = (color & 0x00FF00) >> 8;
var b:int = color & 0x0000FF;
r += (255 * scale)*(r/(r+g+b)); r = (r > 255) ? 255 : r; r = (r < 0) ? 0 : r;
g += (255 * scale)*(g/(r+g+b)); g = (g > 255) ? 255 : g; g = (g < 0) ? 0 : g;
b += (255 * scale)*(b/(r+g+b)); b = (b > 255) ? 255 : b; b = (b < 0) ? 0 : b;
return (r << 16 &amp;amp;amp; 0xff0000) + (g << 8 &amp;amp;amp; 0x00ff00) + (b &amp;amp;amp; 0x0000ff);
}




