AS3 Threshold transition effect using perlin noise


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

Credit for this goes to Terry Paton


Copy this code and paste it in your HTML
  1. package
  2. {
  3. import flash.display.*;
  4. import flash.events.*;
  5. import flash.geom.*;
  6.  
  7. public class AS3Threshold extends MovieClip
  8. {
  9. private var value:Number;
  10. private var _bmpData:BitmapData;
  11. private var _bmpDataPerlin:BitmapData;
  12. private var rect:Rectangle;
  13. private var pt:Point;
  14.  
  15. public function AS3Threshold():void
  16. {
  17.  
  18. }
  19.  
  20. public function startEffect(_clip:MovieClip):Bitmap
  21. {
  22. // capture the _clip as a bitmap
  23. _bmpData = new BitmapData(_clip.width,_clip.height,true);
  24. _bmpData.draw(_clip);
  25. _bmpDataPerlin = new BitmapData(_clip.width,_clip.height,false);
  26. _bmpDataPerlin.perlinNoise(50,50,2,1,true,true,7,true);
  27. value = 1;
  28. addEventListener(Event.ENTER_FRAME, applyEffect);
  29. var _bmp:Bitmap = new Bitmap(_bmpData);
  30. rect = new Rectangle(0,0,_bmpDataPerlin.width,_bmpDataPerlin.height);
  31. pt = new Point(0,0);
  32. return _bmp;
  33. }
  34.  
  35. public function applyEffect(e:Event):void
  36. {
  37. value -= .01;
  38. if (value < .01) {
  39. removeEventListener(Event.ENTER_FRAME,applyEffect);
  40. } else {
  41.  
  42. //var threshold:uint = 0x7F000000;
  43. var threshold:uint = 0xFFFFFF;
  44. var color:uint = 0x00FF00;
  45. var maskColor:uint = 0xffffff;
  46. _bmpData.threshold(_bmpDataPerlin, rect, pt, ">=", (value *threshold), color, maskColor, false);
  47. }
  48. }
  49. }
  50. }
  51.  
  52. // Usage Example
  53. //
  54. // import AS3Threshold;
  55. // var as3Threshold:AS3Threshold = new AS3Threshold();
  56. // myMovieClip.gotoAndStop(1);
  57. // var bmp:Bitmap = as3Threshold.startEffect(myMovieClip);
  58. // addChild(bmp);
  59. // myMovieClip.gotoAndStop(2);

URL: http://www.terrypaton.com/as3-threshold-transition-effect/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.