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

forked from: forked from: 渦巻

渦、台風っぽく
高速化しないと重いな
ブラーもかけたいかも
じっと見てると目をまわします
/**
 * Copyright hacker_w2kqj15r ( http://wonderfl.net/user/hacker_w2kqj15r )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/n2QX
 */

// forked from yd_niku's forked from: 渦巻
// forked from okoi's 渦巻
//
//	渦、台風っぽく
//	高速化しないと重いな
//	ブラーもかけたいかも
//	じっと見てると目をまわします
//
package 
{
	import flash.display.*;
	import flash.geom.*;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author okoi
	 */
	import flash.filters.BlurFilter;
	import flash.events.MouseEvent;
	import flash.accessibility.Accessibility;
	import flash.filters.BitmapFilter;
	public class Main extends Sprite 
	{
		private var spire:Spire;
		private static const POWDER_NUM:int = 10000;
		
		private var _container:Bitmap;
		private var _firstPowder:Powder;
		private var _canvas:BitmapData;
		
		private var _filter:BitmapFilter;
		private var _gain:ColorTransform;
		
		[SWF(frameRate=120)]
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			// entry point
			spire = new Spire();
			
			_container = new Bitmap();
			_container.scaleX = _container.scaleY = 2;
			addChild( _container );
			
			_filter = new BlurFilter(2,2);
			_gain = new ColorTransform(0.97,0.97,0.99,1, -2, -2, 4 );
			
			setupDisplay();
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseHandler);
			stage.addEventListener(MouseEvent.MOUSE_UP,mouseHandler);
			addEventListener( Event.ENTER_FRAME, EnterFrame );
			stage.addEventListener(Event.RESIZE,resizeHandler);
		}
		
		private function mouseHandler(e:MouseEvent):void {
			switch(e.type) {
				case MouseEvent.MOUSE_UP:
					Powder.speed = 1;
				break;
				case MouseEvent.MOUSE_DOWN:
					Powder.speed = 6;
				break;
				case MouseEvent.MOUSE_MOVE:
					Powder.speed++;
				break;
			}
		
		}
		
		private function EnterFrame(e:Event):void {
			spire.Update( stage.mouseX, stage.mouseY );
			
			var c:uint = 0xFFFFFF;
			
			_canvas.lock();
			_canvas.colorTransform( _canvas.rect, _gain );
			
			var powder:Powder = _firstPowder;
			do{
				powder.Move( spire );
				_canvas.setPixel(powder.posX>>1, powder.posY>>1,c );
			}
			while( (powder = powder.next) != null );
			
			_canvas.applyFilter( _canvas, _canvas.rect, o, _filter );
			_canvas.unlock();
		}
		
		private var o:Point = new Point();
		private function resizeHandler(e:Event):void{
			setupDisplay();
		}
		
		private function setupDisplay():void{
			_firstPowder = null;
			
			var powder:Powder, pre:Powder;
			var sw:Number = stage.stageWidth;
			var sh:Number = stage.stageHeight;
			
			for ( var i:int = 0; i < POWDER_NUM; i++ )
			{
				var x:Number = Math.random() * sw;
				var y:Number = Math.random() * sh;
				powder = new Powder(x, y, int(Math.random() * 1000));
				if( !_firstPowder ) _firstPowder = powder; 
				if( pre ) pre.next = powder;
				pre = powder;
			}
			if( _canvas ) {
				_canvas.dispose();
				_canvas = null;
			}
			_canvas = new BitmapData( sw>>1, sh>>1, false, 0 );
			_container.bitmapData = _canvas;
		}
		
	}
	
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
import flash.display.Stage;

/**
 * 渦エネルギー
 */
class Spire {
	
	public var centerX:int;
	public var centerY:int;
	
	public	var	rotatePower:Number = 10;
	
	/**
	 * 更新
	 * @param	_x
	 * @param	_y
	 */
	public	function Update(_x:int, _y:int):void 
	{
		centerX = _x;
		centerY = _y;
	}
}

/**
 * 渦エネルギーの犠牲となる粉
 */
class Powder {
	
	public var next:Powder;
	
	public	var posX:Number;
	public	var posY:Number;
	public	var defX:Number;
	public	var defY:Number;
	
	public	var life:int;
	public	var alpha:Number = 0;
	
	public static var speed:Number = 2.0;
	
	public	function Powder(_x:Number, _y:Number, _l:int)
	{
		Set(_x, _y, _l);
	}
	
	public	function Set(_x:Number, _y:Number, _l:int):void
	{
		posX = _x;
		posY = _y;
		life = _l;
		defX = _x;
		defY = _y;
		alpha = 1;
	}
	
	public	function Move(s:Spire):void 
	{
		var rnd:Number = Math.random()-0.5;
		var vecX:Number = (posX - s.centerX);
		var vecY:Number = (posY - s.centerY);
		var r:Number = Math.sqrt( vecX * vecX + vecY * vecY );
		var angle:Number = Math.atan2( vecY, vecX ) * 180 / Math.PI;
		var vecX2:Number = Math.cos( (angle + s.rotatePower) * Math.PI / 180 ) * r;
		var vecY2:Number = Math.sin( (angle + s.rotatePower) * Math.PI / 180 ) * r;
		
		vecX = (vecX2 - vecX);
		vecY = (vecY2 - vecY);
		r = Math.sqrt( vecX * vecX + vecY * vecY );
		
		vecX /= r;
		vecY /= r;
		
		posX += vecX * 4 * speed + rnd*2;
		posY += vecY * 1 * speed + rnd*2;
	
		life--;
		if ( life <= 0 )
		{
			posX = defX;
			posY = defY;
			life = 1000 + Math.random()*100>>0;
			alpha = 0;
		}
		if ( alpha < 1 )	alpha += 0.1;
		
	}
}