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

Moire

Get Adobe Flash player
by hrtsgt 22 May 2009
/**
 * Copyright hrtsgt ( http://wonderfl.net/user/hrtsgt )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9ZL4
 */

package{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.utils.*;
	import flash.filters.*;
	[SWF(width=465, height=465, backgroundColor=0x0, frameRate=30)]
	
	public class Moire extends Sprite{
		private var wrapper:Sprite;
		private var ary:Array;
		private var bmpd:BitmapData;
		private var bmpd_:BitmapData;
		private var bmp:Bitmap;
		private var timer:Timer;
		static const CIRCLE_MAX:uint = 50;
		static const GENERATE_INTERVAL:Number = 300;
		static const ROTATE_SPEED:Number = 0.5;
		static const ROTATE_RADIUS:Number = 7;
		
		public function Moire(){
			stage.quality = StageQuality.MEDIUM;
			Wonderfl.capture_delay( 10 );
			wrapper = new Sprite();			
			ary = [];
			bmpd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x0);
			bmpd_ = bmpd.clone();
			bmp = new Bitmap(bmpd);
			addChild( bmp );

			timer = new Timer( GENERATE_INTERVAL, 0);
			timer.start();
			timer.addEventListener( TimerEvent.TIMER, onTimer);//
			this.addEventListener( Event.ENTER_FRAME, update);
		}
		
		private function onTimer( e:TimerEvent ):void{
			var shape:Shape = initShape();
			ary.push( shape );
			wrapper.addChild( shape );
			if( ary.length > CIRCLE_MAX ){
				wrapper.removeChild( ary[0] );
				ary.shift();
			}
		}
		
		private function update( e:Event ):void{
			for(var i:uint=0; i<ary.length; i++){
				var shape:Shape = ary[i]
				shape.scaleX = shape.scaleY += 0.4;
			}
			var matrix:Matrix = new Matrix();
			matrix.translate( stage.stageWidth/2, stage.stageHeight/2);
			bmpd.lock();
			bmpd.fillRect( bmpd.rect, 0x0);
			bmpd.draw( wrapper, matrix);
//			bmpd.applyFilter( bmpd, bmpd.rect, new Point(0, 0), new BlurFilter( 2, 2, 1));
			bmpd_ = bmpd.clone();
			var rad:Number = getTimer()*Math.PI/180*ROTATE_SPEED;
			matrix.translate( Math.cos(rad)*ROTATE_RADIUS - stage.stageWidth/2, Math.sin(rad)*ROTATE_RADIUS - stage.stageHeight/2);
			bmpd.draw( bmpd_, matrix, null, BlendMode.ADD);
			bmpd.unlock();
		}
		
		private function initShape():Shape{
			var shape:Shape = new Shape();
			shape.graphics.lineStyle( 1, 0x666666, 1, true, LineScaleMode.NONE);
			shape.graphics.beginFill( 0x0, 0);
			shape.graphics.drawCircle( 0, 0, 2);
			shape.graphics.endFill();
			return shape;
		}
	
	}
}