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

Tentacle sphere

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

package 
{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.display.Bitmap;
	import flash.filters.BlurFilter;
	import flash.display.BitmapData;
	import flash.geom.Point;
	
	public class Main extends MovieClip {
		
	[SWF(backgroundColor=0xffffff, frameRate=50, height=750, width=750)]
		
	
	public var BMD:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true, 0xfffffffff);	
	public var B:Bitmap 	   = new Bitmap(BMD);
	public var bf:BlurFilter = new BlurFilter(2,2,1);
	public var maxDist:Number = (stage.stageWidth/2);
	public var topSpeed:Number = .1;
	public var maxCurve:Number = .5;
	public var totalIterations:int = 200;
	public var count:int = 0;
	public var alive:int = 0;
	public var minAlpha:Number = 0.1;
	public var blurCount:int = 0;
	public var blurEveryX:int = 100;
	public var midX:Number = stage.stageWidth/2;
	public var midY:Number = stage.stageHeight/2;
	
	public function Main():void{
                Wonderfl.capture_delay( 30 );
		addChild(B);
		addEventListener(Event.ENTER_FRAME, DrawBMD);
		makeCirc(50);
	}

	public function makeCirc(num:int):void{
		for(var i:int = 0;i<num; i++){
			alive+=1;
			
			//var C:Circ = new Circ();
			var C:MovieClip  = new MovieClip();

		    C.graphics.lineStyle(2, 0x000000);
		    //C.graphics.beginFill((0xffffff/num)*i, .5);
                    C.graphics.beginFill(0xffffff, .75);
     		    C.graphics.drawCircle(0, 0, 25);
		
			C.x = midX;
			C.y = midY;
			C.speedX = (Math.random()*(topSpeed*2))-topSpeed;
			C.speedY = (Math.random()*(topSpeed*2))-topSpeed;
			C.alpha = 0.5;
			
			addChild(C);
			C.addEventListener(Event.ENTER_FRAME, moveCirc);
		}
	}

	public function resetCirc(Circ:*):void{
		if(count<totalIterations){
			Circ.x = midX;
			Circ.y = midY;
			Circ.scaleX = Circ.scaleY = 1;
			Circ.speedX = (Math.random()*(topSpeed*2))-topSpeed;
			Circ.speedY = (Math.random()*(topSpeed*2))-topSpeed;
			count++;
			blurCount++;
		}
	else{
		Circ.removeEventListener(Event.ENTER_FRAME, moveCirc);
		Circ.parent.removeChild(Circ);
		alive-=1;
			if(alive==0){
				trace("its over!");
			}
		}
	}

	public function moveCirc(e:Event):void{
		var Circ:* = e.currentTarget;
		
		//Circ.rotation = Circ.x;
		
		Circ.accX  = (Math.random()*(maxCurve*2))-maxCurve
		Circ.accY  = (Math.random()*(maxCurve*2))-maxCurve
		
		Circ.speedX += Circ.accX/10;
		Circ.speedY += Circ.accY/10;
		
		Circ.x+=Circ.speedX;
		Circ.y+=Circ.speedY;
		
		var dist:Number = Math.sqrt(((Circ.x-midX)*(Circ.x-midX))+((Circ.y-midY)*(Circ.y-midY)));
			
		Circ.scaleX = Circ.scaleY = map(dist,0,maxDist,1,0);
		if(Circ.scaleX<=0){resetCirc(Circ)}
	}

	public function DrawBMD(e:Event):void{
		BMD.draw(this);
	
		if(blurCount==blurEveryX){
			BMD.applyFilter(BMD, BMD.rect, new Point(0,0), bf);
			blurCount = 0;
		}
	}
	public function map(v:Number, a:Number, b:Number, x:Number = 0, y:Number = 1):Number {
		return (v == a) ? x : (v - a) * (y - x) / (b - a) + x;
	}
	}
}