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

code on 2008-12-25

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.BlendMode;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BlurFilter;
	import flash.filters.DisplacementMapFilter;
	import flash.filters.DisplacementMapFilterMode;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	
	public class Main extends Sprite
	{
		private static const LEVEL:uint = 1;
		private static const BLUR:BlurFilter = new BlurFilter(5, 5, BitmapFilterQuality.LOW);
		
		private var container:Sprite;
		private var originalBmd:BitmapData;
		private var bmd:BitmapData;
		private var bmp:Bitmap;
		
		private var radian:Number = .0;
		private var radius:Number = 200.;
		private var sx:Number = .0;
		private var sy:Number = .0;
		
		private var count:int = 0;
		
		
		[SWF(frameRate="30")]
		
		public function Main()
		{
			graphics.beginFill(0x000000);
			graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			graphics.endFill();
			
			container = new Sprite();
			container.filters = [BLUR];
			
			drawRect();
			
			container.x = (this.width - container.width) / 2;
			container.y = (this.height - container.height) / 2;
			
			addChild(container);
			
			originalBmd = new BitmapData(container.width, container.height, true, 0x00CCCCCC);
			
			var seed:Number = Math.floor(Math.random() * 10);
			var channels:uint = BitmapDataChannel.RED | BitmapDataChannel.GREEN | BitmapDataChannel.BLUE;
			originalBmd.perlinNoise(200, 200, 10, seed, false, true, channels, false, null);
			
			bmd = originalBmd.clone();
			bmp = new Bitmap(bmd);
			bmp.blendMode = BlendMode.HARDLIGHT;
			
			container.addChild(bmp);
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
			addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		private function drawRect():void
		{
			container.graphics.clear();
			container.graphics.beginFill(Math.random() * 0xffffff);
			container.graphics.drawRect(0, 0, stage.stageWidth * 0.95, stage.stageHeight * 0.95);
			container.graphics.endFill();
		}
		
		
		private function enterFrameHandler(event:Event):void
		{
			drawRect();
			
			radian += Math.PI / radius;
			
			var mx:Number = stage.stageWidth / 2 - stage.mouseX;
			var my:Number = stage.stageHeight / 2 - stage.mouseY;
			
			sx += (mx * Math.cos(radian) * 5 - sx) * 0.1;
			sy += (my * Math.sin(radian) * 5 - sy) * 0.1;
			
			
			var mapFilter:DisplacementMapFilter = new DisplacementMapFilter(bmd, new Point(), BitmapDataChannel.BLUE, BitmapDataChannel.BLUE, sx, sy, DisplacementMapFilterMode.IGNORE, 0, 0);
			bmp.filters = [mapFilter];
			
			var mat:Matrix = new Matrix();
			mat.translate(container.x - mx, container.y - my);
			
			bmd.draw(this, mat);
			
			bmd.applyFilter(bmd, bmd.rect, new Point(), mapFilter);
		}
		
		private function clickHandler(event:MouseEvent):void
		{
			bmd.draw(originalBmd);
		}
	}
}