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

flash on 2009-3-18

Get Adobe Flash player
by hiro_rec 17 Mar 2009
    Embed
package
{
	import __AS3__.vec.Vector;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	
	[SWF( backgroundColor='0xFFFFFF', width='456', height='456', frameRate='30')]
	
	public class Main extends Sprite
	{
		private var metaBallList:Vector.<MetaBall> = new Vector.<MetaBall>();
		
		
		public function Main()
		{
			createMetaBalls();
			
			addEventListener(Event.ENTER_FRAME, render);
		}
		
		private function createMetaBalls():void
		{
			for (var i:int = 1; i <= 5; i++)
			{
				var metaBall:MetaBall =
					addChildAt(new MetaBall(stage.stageWidth, stage.stageHeight, 15 * i - i, 1, Math.random() * 0xFFFFFF), 0) as MetaBall;
				
				metaBallList.push(metaBall);
			}
		}
		
		private function render(event:Event):void
		{
			for each (var metaBall:MetaBall in metaBallList)
			{
				metaBall.render();
			}
		}
	}
}

import flash.display.Sprite;	

	class Circle extends Sprite
	{
		public var index:int = 0;
		
		
		public function Circle(index:int, radius:int, color:uint = 0x000000)
		{
			this.index = index;
			
			this.graphics.beginFill(color);
			this.graphics.drawCircle(0, 0, radius);
		}
	}

import __AS3__.vec.Vector;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BlurFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	
	class MetaBall extends Sprite
	{
		private var _width:int, _height:int;
		private var baseRadius:int;
		private var quality:uint;
		private var color:uint;
		
		private var circleList:Vector.<Circle> = new Vector.<Circle>();
		private var container:Sprite;
		private var metaBall:Bitmap;
		private var metaBallBmd:BitmapData;
		
		
		public function MetaBall(_width:int, _height:int, baseRadius:int, quality:uint = 1, color:uint = 0x000000)
		{
			this._width = _width;
			this._height = _height;
			this.baseRadius = baseRadius;
			this.quality = quality;
			this.color = color;
			
			container = new Sprite();
			
			metaBall = new Bitmap();
			addChild(metaBall);
			
			createCircles();
		}
		
		private function createCircles():void
		{
			for (var i:int = 1; i <= quality * 10; i++)
			{
				var circle:Circle = new Circle(i, baseRadius + (i * 1.5 / 30), color);
				
				circle.filters = [new BlurFilter(60, 60, BitmapFilterQuality.LOW)];
				
				container.addChild(circle);
				circleList.push(circle);
			}
		}
		
		private function updateBitmapData():BitmapData
		{
			if (metaBallBmd) metaBallBmd.dispose();
			
			return new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
		}
		
		public function render():void
		{
			moveCircle();
			
			metaBallBmd = updateBitmapData();
			
			var rect:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
			var point:Point = new Point();
			
			metaBallBmd.draw(container);
			
			metaBallBmd.threshold(metaBallBmd, rect, point, "<", 0xCC000000, 0x00FFFFFF, 0xFF000000, false);
			//metaBallBmd.applyFilter(metaBallBmd, rect, point, new BlurFilter(2, 2, BitmapFilterQuality.LOW));
			
			metaBall.bitmapData = metaBallBmd;
			metaBall.smoothing = true;
		}
		
		private function moveCircle():void
		{
			for each (var circle:Circle in circleList)
			{
				circle.x += (mouseX - circle.x) * ((circle.index) * 0.02);
				circle.y += (mouseY - circle.y) * ((circle.index) * 0.02);
			}
		}
	}