forked from: forked from: forked from: 向心力
...
@author 9re
// forked from 9re's forked from: forked from: 向心力
// forked from 9re's forked from: 向心力
// forked from 9re's 向心力
package
{
import flash.display.MovieClip;
import flash.display.Shape;
import flash.events.Event;
/**
* ...
* @author 9re
*/
public class CircularMotion extends MovieClip
{
private const KX:Number = 0.05;
private const KY:Number = 0.07;
private const C:Number = 0.008;
private const R:Number = 150;
private var _shp:Shape;
private var _vx:Number = 0;
private var _vy:Number = 0;
private var _x:Number = R;
private var _y:Number = R;
private var _cx:int;
private var _cy:int;
public function CircularMotion()
{
_shp = new Shape();
_shp.graphics.beginFill(0);
_shp.graphics.drawCircle(0, 0, 15);
_shp.graphics.endFill();
_cx = stage.stageWidth / 2;
_cy = stage.stageHeight / 2;
_shp.x = _cx + R;
_shp.y = _cy + R;
graphics.lineStyle(1, 0xff0000, 0.3);
graphics.moveTo(_shp.x, _shp.y);
addChild(_shp);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(e:Event):void
{
_vx -= (_shp.x - _cx) * KX + C * _x;
_x += _vx;
_vy -= (_shp.y - _cy) * KY + C * _y;
_y += _vy;
_shp.x = _cx + _x;
_shp.y = _cy + _y;
//_shp.y += (_shp.x - stage.stageWidth / 2) * K;
graphics.lineTo(_shp.x, _shp.y);
}
}
}