+ Reply to Thread
Results 1 to 2 of 2

Digital negative image with Actionscript 3.0

This is a discussion on Digital negative image with Actionscript 3.0 within the Tutorials forums, part of the Flash English category; You need to apply a digital negative effect on one or more images? This article will show you how to ...

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,762
    Rep Power
    11

    Digital negative image with Actionscript 3.0

    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 !

  2. #2
    Junior Member Settled In shyraza is on a distinguished road
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Smile plz make a fla for it

    plz make a fla for it

+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. get the correct Big image
    By davids701124 in forum Flash English
    Replies: 0
    Last Post: 05-04-10, 07:49
  2. Replies: 1
    Last Post: 26-01-10, 12:23
  3. Replies: 12
    Last Post: 25-11-09, 07:36
  4. How do I target an image?
    By FuglyBastard in forum Actionscript 3.0 newbies
    Replies: 0
    Last Post: 21-11-09, 16:22
  5. Resize image
    By bulga in forum Actionscript 3.0 base
    Replies: 8
    Last Post: 10-03-08, 05:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts