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

MetaBall

Get Adobe Flash player
by hiro_rec 25 Dec 2008
package
{
	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.filters.GlowFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	

	public class Main extends Sprite
	{	
		private var bmd:BitmapData;
		private var bmp:Bitmap = new Bitmap();
		
		
		public function Main()
		{
			createBalls(40);
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function createBalls(max:uint):void
		{
			for(var i:int=0; i< max; i++)
			{
				var ball:MoveBall = new MoveBall(Math.random() * 60 + 10, Math.random() * 10 + 1);
				ball.x = Math.random() * stage.stageWidth;
				ball.y = Math.random() * stage.stageHeight;
				ball.filters = [new BlurFilter(60, 60, BitmapFilterQuality.LOW)];
				addChild(ball);
			}
		}
		
		private function enterFrameHandler(event:Event):void
		{
			if(bmd) bmd.dispose();
			
			bmd = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00FF0000);
			bmd.draw(stage);
			bmp.bitmapData = bmd;
			
			var rect:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
			var point:Point = new Point();
			
			bmd.threshold(bmd, rect, point, "<", 0xCC000000, 0xFFFF00FF, 0xFF000000, false);
			bmd.applyFilter(bmd, rect, point, new BlurFilter(2, 2, BitmapFilterQuality.MEDIUM));
			//bmd.applyFilter(bmd, rect, point, new GlowFilter(0xff0000, 1, 1, 1, 1, 1, false, true));
			addChild(bmp);
		}
	}
}

import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;

class MoveBall extends Sprite
{	
	private var speed:Number;
	public var vect:int = 1;
	
	
	public function MoveBall(radius:Number, speed:Number = 1)
	{
		this.speed = speed;
		
		this.graphics.beginFill(0x000000);
		this.graphics.drawCircle(0, 0, radius);
		
		addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}
	
	private function enterFrameHandler(event:Event):void
	{
		this.x += speed * vect;
		this.y += speed * vect;
		
		if(x > this.stage.stageWidth || y > this.stage.stageHeight || x < 0 || y < 0)
			vect *= -1;
	}
}