You need to apply a digital negative effect on one or more images?
This article will show you how to do it using a digital negative matrix applied to the image with the ColorMatrixFilter class.
Applying to it an interval, we could play with it quite a lot...
In this example I apply 3 sliders to check the red, green and blue channels of the digital negative matrix.
Let's look at the example:
I create a FLA and save it as 'negativo.fla' in which,
I create 2 instances MovieClip named respectively 'img_mc' and 'pic_mc' inside which I insert an image.
I create 3 instances of the Slider component named respectively 'red_slider', 'green_slider', 'blue_slider'.
I create a Document Class, an AS file saved as 'Negativo.as', implemented the following way:
Code:
package
{
import flash.display.MovieClip;
import flash.filters.ColorMatrixFilter;
import flash.events.Event;
public class Negativo extends MovieClip
{
public function Negativo()
{
init();
listener();
}
private function init():void
{
stage.frameRate=31;
pic_mc.filters=[new ColorMatrixFilter(
[-1,0,0,0,255,
0,-1,0,0,255,
0,0,-1,0,255,
0,0,0,1,0])];
red_slider.minimum=0;
red_slider.maximum=255;
red_slider.value=255;
green_slider.minimum=0;
green_slider.maximum=255;
green_slider.value=255;
blue_slider.minimum=0;
blue_slider.maximum=255;
blue_slider.value=255;
}
private function listener():void
{
pic_mc.addEventListener(Event.ENTER_FRAME,go);
function go(e:Event):void
{
e.target.filters=[new ColorMatrixFilter(
[-1,0,0,0,red_slider.value,
0,-1,0,0,green_slider.value,
0,0,-1,0,blue_slider.value,
0,0,0,1,0])];
}
}
}
}
The result:
Let's analise the code.
Methods
init();
I impost the frame rate
stage.frameRate=31;
I apply the negative matrix to 'pic_mc' using a new instance of the ColormatrixFilter class and assigning to it the filters property of the MovieClip (in fact 'pic_mc')
pic_mc.filters=[new ColorMatrixFilter(
[-1,0,0,0,255,
0,-1,0,0,255,
0,0,-1,0,255,
0,0,0,1,0])];
for each slider I assign a minimum and maximum value (minimum zero, maximum 255...the maximum value of the RGB scale) and also a starting value
red_slider.minimum=0;
red_slider.maximum=255;
red_slider.value=255;
green_slider.minimum=0;
green_slider.maximum=255;
green_slider.value=255;
blue_slider.minimum=0;
blue_slider.maximum=255;
blue_slider.value=255;
listener();
I add an interval ENTER_FRAME
pic_mc.addEventListener(Event.ENTER_FRAME,go);
go(e:Event):void
I apply the negative matrix based on the values obtained from the positions of the three sliders
e.target.filters=[new ColorMatrixFilter(
[-1,0,0,0,red_slider.value,
0,-1,0,0,green_slider.value,
0,0,-1,0,blue_slider.value,
0,0,0,1,0])];
Stay tuned !