Created
January 31, 2016 11:29
-
-
Save B-Interactive/3f5b802b72980a76e533 to your computer and use it in GitHub Desktop.
A HaXe method for applying a decimal (0 to 1) alpha to a 32bit ARGB hexadecimal colour, returning the recalculated 32bit ARGB hexadecimal value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Merges a hexidecimal colour with a 0-1 alpha value and returns a new hexidecimal colour. | |
* | |
* @param Input ARGB colour that alpha will be applied to. Eg: 0xFFFFFFFF (32bit ARGB). | |
* @param Alpha value will be applied to colour. 0 (fully transparent) to 1 (fully opaque). | |
* @return Returns a new ARGB hexidecimal incorporating alpha. | |
*/ | |
public static function mergeAlpha(colour:Int, alpha:Float):Int | |
{ | |
// Bitwise hex extraction. | |
var a:Int = Std.int(colour >>> 24); | |
var r:Int = Std.int(colour >>> 16 & 0xFF); | |
var g:Int = Std.int(colour >>> 8 & 0xFF); | |
var b:Int = Std.int(colour & 0xFF); | |
return Std.int(a*alpha) << 24 | r << 16 | g << 8 | b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment