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

bubbles

/**
 * Copyright MR_WUT4 ( http://wonderfl.net/user/MR_WUT4 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8rbD
 */

package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.filters.BevelFilter;
	import flash.filters.BlurFilter;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	public class Bubbles extends Sprite 
    {
		private var bgc:uint;
		private var dtc:uint;
		private var dta:Number;
		private var stg:Stage;
		private var sth:uint;
		private var stw:uint;
		private var ctx:uint;
		private var cty:uint;
		private var dtw:Number;
		private var dth:Number;
		private var dll:uint;
		private var cnt:Sprite;
		private var dtx:int;
		private var dty:int;
		private var dfx:int;
		private var dfy:int;
		private var blx:uint;
		private var bly:uint;
		private var blv:Number;
		private var dot:Sprite;
		private var dtg:Graphics;
		private var siz:uint;
		private var blf:BlurFilter;
		private var bvf:BevelFilter;
		private var dtl:Array;
		private var rec:Rectangle;
		private var bmd:BitmapData;
		private var bmp:Bitmap;
		
		public function Bubbles()
		{
		    stg = stage;
		    sth = stg.stageHeight;
		    stw = stg.stageWidth;
			
		    dtl = new Array();
		
	        bgc = 0x333333;
		    dtc = 0xbbff44;
				
			var flt:String = GradientType.RADIAL;
			var clr:Array = [0x4D4D4D, 0x333333];
			var alp:Array = [1, 1];
			var rat:Array = [0x00, 0xFF];
				
			var mat:Matrix = new Matrix();
			mat.createGradientBox(stw, sth, 0, 0, 0);
				
			var spm:String = SpreadMethod.PAD;
				
			graphics.beginGradientFill(flt, clr, alp, rat, mat, spm);  
			graphics.drawRect(0, 0, stw, sth);
			graphics.endFill();
				
				
		    dta = .6;
		    ctx = stw * .5;
		    cty = sth * .5;
						
		    cnt = new Sprite();		
		    blf = new BlurFilter(0, 0, 1);
		    bvf = new BevelFilter(8, 45, 0xFFFFFF, .05, 0x000000, .05, 3, 3, 1, 1);								
		    rec = new Rectangle(0, 0, stw, sth);					
		    bmd = new BitmapData(stw, sth, true, 0x00000000);
		    bmp = new Bitmap(bmd);
					
		    addChild(bmp);
				
		    for(var i:uint = 0; i < 100; ++i)
		    {
				dot = new Sprite();
				dtg = dot.graphics;
					
				siz = 3 + Math.random() * 17;
						
				dot.cacheAsBitmap = true;
							
				dot.alpha = dta;
						
				dtg.beginFill(dtc);
				dtg.drawCircle(- siz * .5, -siz * .5, siz);
				dtg.endFill();
						
				dtx = Math.round(Math.random() * stw);
				dty = Math.round(Math.random() * sth);
						
				dot.x = dtx;
				dot.y = dty;
				dot.filters = [blf, bvf];
						
				cnt.addChild(dot);
						
				dtl.push(dot);
		    }
		
		    dll = dtl.length;
		    
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
			
		private function enterFrameHandler(e:Event):void
		{			
		    for(var i:uint = 0; i < dll; ++i)
		    {
		        dot = Sprite(dtl[i]);
							
				dtw = dot.width;
				dth = dot.height;
								
				dtx = dot.x + Math.round(Math.random() * 2 - 1);
				dty = dot.y + Math.round(Math.random() * 2 - 1) - (100 / dtw);
						
				dtx = (dtx + dtw < 0) ? stw + dtw : (dtx - dtw > stw) ? - dtw : dtx; 
				dty = (dty + dth < 0) ? sth + dth : (dty - dth > sth) ? - dth : dty; 
						
				dot.x = dtx;
				dot.y = dty;
						
				dfx = ctx - dtx;
				dfy = cty - dty;
					
				blx = ((dfx < 0) ? dfx * -1 : dfx) * .1;
				bly = ((dfy < 0) ? dfy * -1 : dfy) * .1;
						
				blv = (blx * bly) * .1;
						
				blf = BlurFilter(dot.filters[0]);		
				blf.blurX = blf.blurY = blv;
					
				dot.filters = [blf, bvf];
		    }
				
		    bmd.fillRect(rec, 0x00000000);
		    bmd.draw(cnt);
		}
	}
}