forked from: forked from: forked from: forked from: うねうね
移植してみた
/**
* Copyright hacker_kdf9a0nu ( http://wonderfl.net/user/hacker_kdf9a0nu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rBnH
*/
// forked from paccer's forked from: forked from: forked from: うねうね
// forked from ay_caramba's forked from: forked from: うねうね
// forked from gunte's forked from: うねうね
// forked from 178ep3's うねうね
//移植してみた
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
public class Arm extends Sprite
{
private var _maxNum:uint = 30;
private var _xList:Array = new Array(_maxNum);
private var _yList:Array = new Array(_maxNum);
private var _aList:Array = new Array(_maxNum);
private var _length:Number = 40;
private var _targetX:Number;
private var _targetY:Number;
public function Arm()
{
for(var i:uint=0; i<_maxNum; i++)
{
_xList[i] = 0;
_yList[i] = 0;
_aList[i] = 0;
}
_yList[_maxNum-1] = stage.stageHeight;
addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event):void
{
this.graphics.clear();
Angle(0,mouseX,mouseY);
var i:uint;
for(i=1; i<_maxNum; i++)
{
Angle(i,_targetX,_targetY);
}
for(i=_maxNum-1; i>=1; i--)
{
Position(i,i-1);
}
for(i=0; i<_maxNum; i++)
{
draw(_xList[i],_yList[i],_aList[i],(i+1)*2,i);
}
}
private function Angle(i:uint, _x:Number, _y:Number):void
{
var dx:Number = _x - _xList[i];
var dy:Number = _y - _yList[i];
_aList[i] = Math.atan2(dy,dx);
_targetX = _x - Math.cos(_aList[i]) * _length;
_targetY = _y - Math.sin(_aList[i]) * _length;
}
private function Position(a:uint,b:uint):void
{
_xList[b] = _xList[a] + Math.cos(_aList[a]) * _length;
_yList[b] = _yList[a] + Math.sin(_aList[a]) * _length;
}
private function draw(_x:Number, _y:Number, _a:Number, _s:Number,i:uint):void
{
this.graphics.lineStyle(_s,0x000000,0.5);
this.graphics.moveTo(_x,_y);
var p:Point = Point.polar(_length,_a);
this.graphics.lineTo(p.x+_x ,p.y+_y);
this.graphics.endFill();
}
}
}