In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

particleDispersion

Get Adobe Flash player
by 0xABCDEF 27 Mar 2010
/**
 * Copyright 0xABCDEF ( http://wonderfl.net/user/0xABCDEF )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rnW3
 */

package {
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import flash.filters.DisplacementMapFilter;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	[SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
	public class particleDispersion extends Sprite {
		public function particleDispersion() {
			stage.addEventListener(Event.ENTER_FRAME,ef);
			var s:Shape = new Shape();
			var ps:Sprite = new Sprite();
			var sa:Array = new Array();
			const sw:uint = 465;
			const sh:uint = 465;
			var bd:BitmapData = new BitmapData(sw,sh,false,0);
			var b:Bitmap = new Bitmap(bd);
			stage.addChild(b);
			const p:Point = new Point();
			const bf:BlurFilter = new BlurFilter(2,2,6);
			const ct:ColorTransform = new ColorTransform(0.9,0.9,0.9);
			var df:DisplacementMapFilter = new DisplacementMapFilter(bd,p,1,1,0,0,"color");
			var a:Number = 0;
			var pa:Array = new Array();
			var i:int;
			var po:Number;
			function polar(p:Number,d:Number):Point{
				var xm:Number = Math.cos(d)*p;
				var ym:Number = Math.sin(d)*p;
				return (new Point(xm,ym)); 	
			}
			function ef(e:Event):void {
				po = Math.random();
				s.graphics.clear();
				pa.push({x:sw/2,y:sh/2,a:Math.random()*360,r:po*30,c:(Math.random()*0xFFFFFF)|0x333333});
				pa.push({x:sw/2,y:sh/2,a:Math.random()*360,r:po*30,c:(Math.random()*0xFFFFFF)|0x333333});
				pa.push({x:sw/2,y:sh/2,a:Math.random()*360,r:po*30,c:(Math.random()*0xFFFFFF)|0x333333});
				pa.push({x:sw/2,y:sh/2,a:Math.random()*360,r:po*30,c:(Math.random()*0xFFFFFF)|0x333333});
				pa.push({x:sw/2,y:sh/2,a:Math.random()*360,r:po*30,c:(Math.random()*0xFFFFFF)|0x333333});
				for(i=0;i<pa.length;i++){
					s.graphics.beginFill(pa[i].c);
					s.graphics.drawCircle(pa[i].x,pa[i].y,pa[i].r);
					s.graphics.endFill();
					s.blendMode = "add";
					ps.addChild(s);
					sa.push(s);
					pa[i].x += polar(pa[i].r,pa[i].a).x;
					pa[i].y += polar(pa[i].r,pa[i].a).y;
					pa[i].r -= 1;
					if((pa[i].x>sw)||(pa[i].x<0)||(pa[i].y>sh)||(pa[i].y<0)||(pa[i].r<=0.5)){
						ps.removeChild(sa[i]);
						pa.splice(i,1);
					}
				}
				a += (Math.random()*8-4)*po;
				df.scaleX = polar(po*20,a).x;
				df.scaleY = polar(po*20,a).y;
				bd.applyFilter(bd,bd.rect,p,bf);
				bd.applyFilter(bd,bd.rect,p,df);
				bd.draw(ps);
				bd.colorTransform(bd.rect,ct);
			}
		}
	}
}