Return to Snippet

Revision: 40913
at February 9, 2011 22:26 by adrianparr


Initial Code
var red:uint = 0xFF0000;
var green:uint = 0x00FF00;
var average:uint = averageColour(red, green);
trace("average: " + average);
var averageCSS:String = "#" + average.toString(16).toUpperCase();
trace("averageCSS: " + averageCSS);

function averageColour(colour1:uint, colour2:uint):uint
{
	var averageRed:uint = (((colour1 >> 16) & 0xFF) + ((colour2 >> 16) & 0xFF)) / 2;
	var averageGreen:uint = (((colour1 >> 8) & 0xFF) + ((colour2 >> 8) & 0xFF)) / 2;
	var averageBlue:uint = ((colour1 & 0xFF) + (colour2 & 0xFF)) / 2;
	var hex:uint = averageRed << 16 | averageGreen << 8 | averageBlue;
	return hex;
}

// OUTPUT
// average: 8355584
// averageCSS: #7F7F00

Initial URL

                                

Initial Description

                                

Initial Title
AS3 Average Colour Between Two Colours (My version)

Initial Tags
css, color

Initial Language
ActionScript 3