Skip to content

Instantly share code, notes, and snippets.

@Fishrock123
Last active December 26, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fishrock123/7063688 to your computer and use it in GitHub Desktop.
Save Fishrock123/7063688 to your computer and use it in GitHub Desktop.
UNFINISHED. WIP. ETC. Code by "graphxdziner" on board.flashkit.com translated to js for use with pixi.js
/*
* @author "graphxdziner" on board.flashkit.com
* Source: http://board.flashkit.com/board/showthread.php?728847-convert-hex-value-to-colormatrix-array&s=a432383a54d4eeed74bf800b22ee0f83&p=3854541&viewfull=1#post3854541
*/
function setColor(mc, r, g, b, a)
{
var matrix =
[ r, 0, 0, 0
, 0, g, 0, 0
, 0, 0, b, 0
, 0, 0, 0, a ];
var filter:BitmapFilter = new ColorMatrixFilter(matrix);
mc.filters = new Array(filter);
}
function setColorFromHex (mc, hex, alpha)
{
// var alpha = (argb & 0xFF000000) >>> 24; // if this was argb
var r = ((rgb & 0x00FF0000) >>> 16) / 255
, g = ((rgb & 0x0000FF00) >>> 8) / 255
, b = (rgb & 0x000000FF) / 255
, a = alpha/100;
setColor(mc, r, g, b, a);
}
var alpha = 100;
var color = 0x44DAFF;
setColorFromHex (mc, color, alpha);
//
// EXAMPLE FOUR - CONVERSTION
//
function hexToMatrix(hex, alpha)
{
return [ ((hex & 0x00FF0000) >>> 16) / 255 /*red*/, 0, 0, 0
, 0, ((hex & 0x0000FF00) >>> 8) / 255 /*green*/, 0, 0
, 0, 0, (hex & 0x000000FF) / 255 /*blue*/, 0
, 0, 0, 0, (alpha || 100) / 100 ];
}
mc.filters = [ new flash.filters.ColorMatrixFilter ( hexToMatrix ( 0x44DAFF, 100 ) ) ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment