Mark Timothy
Mark Timothy

Reputation: 1814

how to make a given color darker

I need to darken a given color by given percentage, if the percentage is 1 the black color should be returned and if the percentage is 0 the originalColor should be returned.

private  function getDarkenedColor ( originalColor : uint, darkPercentage : Number = 0.5 ) : uint {

var red : uint = UtilColor.extractColor( originalColor, UtilColor.EXTRACT_COLOR_RED );
var blue : uint = UtilColor.extractColor( originalColor, UtilColor.EXTRACT_COLOR_BLUE );
var green : uint = UtilColor.extractColor( originalColor, UtilColor.EXTRACT_COLOR_GREEN );

return (new ColorTransform()).color; //please complete this line

}

Upvotes: 0

Views: 99

Answers (1)

Alvein
Alvein

Reputation: 141

if the percentage is 1 the black color should be returned and if the percentage is 0 the originalColor should be returned

Then it is a ratio, not a percentage

Therefore you just have to multiply each component (red, blue, green) by your given ratio.

Upvotes: 1

Related Questions