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

うねうねライン

うねうねライン
@author okoi
Get Adobe Flash player
by okoi 27 Apr 2010
/**
 * Copyright okoi ( http://wonderfl.net/user/okoi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/e4zW
 */

//
//	うねうねライン
//	@author okoi
//
package 
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	public class Main extends Sprite 
	{
		private var list:Array = new Array();
		private static const PATHNUM:int = 360 * 2;
		
		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);
			// entry point
			
			for ( var i:int = 0; i < PATHNUM; i++ )
			{
				var obj:Path = new Path();
				obj._x = stage.mouseX;
				obj._y = stage.mouseY;
				obj._angle = i;
				obj._step = i * 10;
				obj._power = i * 50 / 360;
				list.push( obj );
			}
			
			addEventListener( Event.ENTER_FRAME, Update );
		}
		
		private function Update(e:Event):void
		{
			var i:int;
			
			for ( i = 0; i < list.length - 1; i++ )
			{
				if ( i > 0 )
				{
					list[i].Update( list[i - 1]._x, list[i - 1]._y );
				}else
				{
					list[i].Update( stage.mouseX, stage.mouseY );
				}
			}
			
			
			graphics.clear();
			for ( i = 0; i < list.length - 1; i++ )
			{
				graphics.beginFill( 0x0 );
				var obj:Path = list[i];
				graphics.drawCircle( obj._x + obj._px, obj._y + obj._py, 5 );
				graphics.endFill();
			}
		}
		
	}
	
}
import flash.display.MovieClip;
import flash.display.Sprite


class Path {
	
	public	var	_x:Number;
	public	var _y:Number;
	public	var _px:Number;
	public	var _py:Number;
	
	public	var _angle:Number;
	public	var _power:Number;
	public	var _sin:Number;
	public	var _step:int;
	
	
	public	function Path() 
	{
		_power = 10;
		_step = 0;
		_px = 0;
		_py = 0;
	}
	
	/**
	 * 
	 * @param	_tx		目標位置
	 * @param	_ty		目標位置
	 */
	public	function Update(_tx:Number, _ty:Number):void 
	{
		_sin = Math.sin( _step * Math.PI / 180 );
		
		if ( !((_ty - _y) == 0 && (_tx - _x) == 0) )
		{
			var angle2:Number = Math.atan2( _ty - _y, _tx - _x ) * 180 / Math.PI;
			_angle = angle2;
		}
		
		_px = Math.cos( (_angle + 90) * Math.PI / 180 ) * (_sin * _power);
		_py = Math.sin( (_angle + 90) * Math.PI / 180 ) * (_sin * _power);
		
		_x += (_tx - _x) / 1.2;
		_y += (_ty - _y) / 1.2;
		
		_step = (_step - 10 + 360) % 360;
	}
	
}