Halftone Effect in Actionscript 3 / Flash


/ Published in: ActionScript 3
Save to your folder(s)

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/


Copy this code and paste it in your HTML
  1. package
  2. {
  3. import flash.display.*;
  4. import flash.events.*;
  5. import flash.filters.*;
  6. import flash.net.*;
  7.  
  8.  
  9.  
  10. public class Halftone extends Sprite
  11. {
  12.  
  13. private var image:Class;
  14.  
  15. private var loader:URLLoader;
  16. private var shader:Shader;
  17. private var filter:ShaderFilter;
  18. private var im:Bitmap;
  19.  
  20. public function Halftone():void
  21. {
  22. var myImage = new MyImage(500,333);
  23. im = new Bitmap(myImage);
  24. addChild(im);
  25. loader = new URLLoader();
  26. loader.dataFormat = URLLoaderDataFormat.BINARY;
  27. loader.addEventListener(Event.COMPLETE, onComplete);
  28. loader.load(new URLRequest("Halftone.pbj")); //Download: http://www.adamcoulombe.info/lab/as3/halftone/Halftone.pbj
  29. }
  30.  
  31. private function onComplete(e:Event):void
  32. {
  33. stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved)
  34.  
  35. }
  36. private function mouseMoved(e):void
  37. {
  38. shader = new Shader(loader.data);
  39. //shader.data.contrast.value = [ 1 ] ;
  40. shader.data.brightness.value = [ stage.mouseX /stage.stageWidth + 1 ];
  41. //shader.data.amount.value = [100];
  42. filter = new ShaderFilter(shader);
  43. im.filters = [filter];
  44. }
  45. }
  46. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.