Posted By

publicbroadcast on 07/21/09


Tagged


Versions (?)

smudge


 / Published in: ActionScript 3
 

  1. [SWF(backgroundColor = 0xCCCCCC)]
  2. var canvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true, 0xFFFFFFFF);
  3. addChild(new Bitmap(canvas));
  4.  
  5. var loader:Loader = new Loader();
  6. loader.load(new URLRequest("http://actionsnippet.com/wp-content/chair.jpg"));
  7. loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
  8. function onComplete(evt:Event):void{
  9. canvas.draw(loader);
  10. }
  11.  
  12. var brush:Shape = new Shape();
  13. var diameter:Number = 120;
  14. var radius:Number = diameter / 2;
  15. var matrix:Matrix = new Matrix();
  16.  
  17. var brushAlpha:BitmapData = new BitmapData(diameter, diameter, true, 0x00000000);
  18. drawRadial();
  19. brushAlpha.draw(brush);
  20.  
  21. var xp:Number = 0, yp:Number = 0, px:Number = 0, py:Number = 0;
  22. var dx:Number, dy:Number;
  23.  
  24. stage.addEventListener(MouseEvent.MOUSE_MOVE, onLoop);
  25. function onLoop(evt:Event):void {
  26. xp = mouseX - radius;
  27. yp = mouseY - radius;
  28. dx = xp - px;
  29. dy = yp - py;
  30. canvas.copyPixels(canvas,
  31. new Rectangle(px, py, diameter, diameter),
  32. new Point(xp, yp), brushAlpha, new Point(0,0), true);
  33. px = xp;
  34. py = yp
  35. }
  36.  
  37. function drawRadial():void{
  38. matrix.createGradientBox(diameter, diameter, 0, 0, 0);
  39. with (brush.graphics){
  40. beginGradientFill(GradientType.RADIAL, [0xFFFFFF, 0xFFFFFF], [1,0], [0, 255], matrix, SpreadMethod.PAD);
  41. drawCircle(radius, radius, radius);
  42. }
  43. }

Report this snippet  

You need to login to post a comment.