Tuesday, March 20, 2012

Flex SDK (AS3) -- The ColorMatrixFilter

the filter will do something like:

- if m is the matrix array...
red   = m[0]*r  + m[1]*g  + m[2]*b  + m[3]*a  + m[4];
green = m[5]*r  + m[6]*g  + m[7]*b  + m[8]*a  + m[9];
blue  = m[10]*r + m[11]*g + m[12]*b + m[13]*a + m[14];
alpha = m[15]*r + m[16]*g + m[17]*b + m[18]*a + m[19];
where...
r = source red,
g = source green,
b = source blue,
a = source alpha,

(ref: http://active.tutsplus.com/tutorials/effects/manipulate-visual-effects-with-the-colormatrixfilter-and-convolutionfilter/)

------------- let's create a firey cloud -----
var bmpPerlin:BitmapData = createPerlinImage(width, height, 5);

// fireup
var fireup:ColorMatrixFilter = new ColorMatrixFilter([1,0.5,0,0,0,
                                                      0,1,0,0,0,
                                                      0,0,0,0,0,
                                                      1,1,0,0,0]);
bmpPerlin.applyFilter(bmpPerlin, bmpPerlin.rect, new Point(), fireup);

---------
to create the perlin  image (http://noypi-linux.blogspot.com/2012/03/flex-sdk-perlin-noise-as3.html)