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

ひも的な何か

Get Adobe Flash player
by demouth 03 Nov 2009
/**
 * Copyright demouth ( http://wonderfl.net/user/demouth )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/bHmj
 */

package  
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	[SWF(frameRate='60')] 
	public class Main extends Sprite
	{
		protected var joints:Vector.<Joint> = new Vector.<Joint>();
		protected var fric:Number = 0.01;
		protected var spring:Number = 0.995;//ばね的なもの?
		protected var range:int = 30;//前後に影響を与える範囲
		protected var num:int = 1;
		
		public function Main() 
		{
			if (this.stage) this.init()
			else this.addEventListener(Event.ADDED_TO_STAGE , this.init);
		}
		
		protected function init(event:Event = null):void
		{
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			this.num = this.stage.stageHeight;
			this.create();
			this.addEventListener(Event.ENTER_FRAME , this.enterFrameHandler);
		}
		
		protected function create():void
		{
			var num:Number = this.num;
			
			for (var i:int = 0; i < num; i++) 
			{
				var j:Joint = new Joint();
				
				//j.x = Math.random()*10 - 5 ;
				j.y = i;
				
				this.joints.push(j);
			}
		}
		
		private function enterFrameHandler(event:Event):void
		{
			this.graphics.clear();
			
			this.calc();
			this.move();
			this.draw();
		}
		
		private function calc():void
		{
			var l:int = this.joints.length;
			for (var i:int = 0; i < l; i++) 
			{
				if (i == 0)
				{
					this.joints[0].x = this.stage.mouseX;
					continue;
				}
				
				var b:int = this.range;
				var a:int = this.range;
				var now:Joint = this.joints[i];
				
				for (var j:int = i-b; j < i+a+1; j++) 
				{
					if (j >= 0 && l > j && j != i)
					{
						var t:Joint = this.joints[j];
						now.sx -= now.x - t.x;
					}
				}
			}
		}
		
		private function move():void
		{
			var l:int = this.joints.length;
			for (var i:int = 0; i < l; i++) 
			{
				var now:Joint = this.joints[i];
				now.x += now.sx * this.fric;
				now.y += now.sy * this.fric;
				now.sx *= this.spring;
				now.sy *= this.spring;
			}
		}
		
		private function draw():void
		{
			var g:Graphics = this.graphics;
			var l:int = this.joints.length;
			
			for (var i:int = 0; i < l; i++) 
			{
				var color:uint = Math.abs(int(this.joints[i].sx/5));
				if(color > 255)color = 255;
				color = color << 16 | color << 8 | color;
				g.beginFill(color);
				g.drawCircle(this.joints[i].x, this.joints[i].y, 1);
				g.endFill();
			}
			
		}
	}

}

class Joint
{
	public var x:Number = 0;
	public var y:Number = 0;
	public var sx:Number = 0;
	public var sy:Number = 0;
}