/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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