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

伸びるひもっぽい何か

参考

bouze's hybrid-brush-05
http://wonderfl.kayac.com/code/ff5d0155b7268a766c3bc22da04be974a0778d0e

...
@author tkinjo
Get Adobe Flash player
by tkinjo 09 Jun 2009
/**
 * Copyright tkinjo ( http://wonderfl.net/user/tkinjo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/yOKY
 */

// forked from tkinjo's ひもっぽい何か
// forked from tkinjo's 点の追従
package  
{
	/**
	 * 参考
	 * 
	 * bouze's hybrid-brush-05
	 * http://wonderfl.kayac.com/code/ff5d0155b7268a766c3bc22da04be974a0778d0e
	 */
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	[SWF(width="465", height="465", frameRate="60", backgroundColor="0xffffff")]
	/**
	 * ...
	 * @author tkinjo
	 */
	public class Main extends Sprite {
		
		// 点の数
		private const dotNum:int = 50;
		
		// 摩擦係数
		private const friction:Number = 0.5;
		
		// 点の半径
		private const dotRadius:uint = 1;
		
		// 点と点との距離
		private const minDistance:uint = 5;
		private const maxDistance:uint = 20;
		
		
		
		
		
		// 点の配列
		private var dots:Array = new Array();
		
		/**
		 * コンストラクタ
		 */
		public function Main() {
			
			// ループカウンタ
			var i:int;
			
			// 点の作成
			for ( i = 0; i < dotNum; i++) {
				
				var dot:Point = new Point( mouseX, mouseY );
				dots.push( dot );
			}
			
			
			
			// フレームごとにループ
			addEventListener(Event.ENTER_FRAME, function( event:Event ):void {
					
					/** --------------------------------------------------
					 * 計算
					 */
					for (i = 0; i < dotNum; i++) {
						
						
						// 座標の算出
						if ( i == 0 ) {
							
							dots[ i ].x = mouseX;
							dots[ i ].y = mouseY;
							
						} else {
							
							// 速度の算出
							var vx:Number;
							var vy:Number;
							
							vx = ( dots[ i - 1 ].x - dots[ i ].x ) * friction;
							vy = ( dots[ i - 1 ].y - dots[ i ].y ) * friction;
							
							// 座標の算出
							dots[ i ].x += vx;
							dots[ i ].y += vy;
							
							
							
							// 距離の調整
							var dx:Number = dots[ i ].x - dots[ i - 1 ].x;
							var dy:Number = dots[ i ].y - dots[ i - 1 ].y;
							var distance:Number = Math.sqrt( dx * dx + dy * dy );
							var angle:Number = Math.atan2( dy, dx );
							
							if( distance < minDistance ) {
								
								dots[ i ].x = dots[ i - 1 ].x + minDistance * Math.cos( angle );
								dots[ i ].y = dots[ i - 1 ].y + minDistance * Math.sin( angle );
								
							} else if ( distance > maxDistance ) {
								
								dots[ i ].x = dots[ i - 1 ].x + maxDistance * Math.cos( angle );
								dots[ i ].y = dots[ i - 1 ].y + maxDistance * Math.sin( angle );
							}
						}
					}
					
					/** --------------------------------------------------
					 * 描画
					 */
					graphics.clear();
					graphics.beginFill( 0 );
					
					for (i = 0; i < dotNum; i++)
						graphics.drawCircle( dots[ i ].x, dots[ i ].y, dotRadius );
					
				} );
		}
	}
}