Recently, I tried some BlendMode in AS3. Thanks to them we can reproduce some cool effects of Photshop.
This is a simple script to do that. I thought it’s a nice effect !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.BlendMode; import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; import flash.filters.BlurFilter; import flash.geom.Point; [SWF(backgroundColor="#000000", frameRate="31", width="600", height="500")] /** * @author Aymeric */ public class MouseFollower extends Sprite { private var _container:Sprite; private var _bData:BitmapData; private var _img:Bitmap; private var _circle:Shape; public function MouseFollower() { _container = new Sprite(); _container.visible = false; this.addChild(_container); _bData = new BitmapData(600, 500, true, 0x00FF00); _img = new Bitmap(_bData); _circle = new Shape(); this.addChild(_img); _container.addChild(_circle); this.addEventListener(Event.ENTER_FRAME, _ef); } private function _ef(evt:Event):void { _circle.graphics.clear(); _circle.graphics.beginFill(Math.random()*0xFFFFFF); _circle.graphics.drawCircle(0, 0, 10); _circle.graphics.endFill(); var diffx:int = mouseX - _circle.x; var diffy:int = mouseY - _circle.y; _circle.x +=diffx * 0.05; _circle.y +=diffy * 0.05; _bData.draw(_container, null, null, BlendMode.ADD); _bData.applyFilter(_bData, _bData.rect, new Point(), new BlurFilter(5, 5, 2)); } } } |
This two lines are important if you want to keep an eye on your CPU usage :
_circle.graphics.clear();
_circle.graphics.endFill();
BlendMode are more than ever CPU’s eater !