Return to Snippet

Revision: 27549
at June 15, 2010 16:39 by adamcoulombe


Initial Code
package
{
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.net.*;
	


	public class Halftone extends Sprite
	{

		private var image:Class;
		
		private var loader:URLLoader;
		private var shader:Shader;
		private var filter:ShaderFilter;
		private var im:Bitmap;
		
		public function Halftone():void
		{	
			var myImage = new MyImage(500,333);
			im = new Bitmap(myImage);
			addChild(im);
			loader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("Halftone.pbj")); //Download: http://www.adamcoulombe.info/lab/as3/halftone/Halftone.pbj
		}
		
		private function onComplete(e:Event):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved)

		}
		private function mouseMoved(e):void
		{
			shader = new Shader(loader.data);
			//shader.data.contrast.value = [ 1 ] ;
			shader.data.brightness.value = [ stage.mouseX /stage.stageWidth + 1   ];
			//shader.data.amount.value = [100];
			filter = new ShaderFilter(shader);
			im.filters = [filter];		
		}
	}
}

Initial URL
http://www.adamcoulombe.info/lab/as3/halftone/

Initial Description
This is a demo of a halftone effect for AS3. It requires a halftone filter file. You can download all the files required for this at http://www.adamcoulombe.info/lab/as3/halftone/

Initial Title
Halftone Effect in Actionscript 3 / Flash

Initial Tags
actionscript, flash

Initial Language
ActionScript 3