Practice05 - Elliptic Motion
reference from
http://gihyo.jp/dev/serial/01/as3/0022
/**
* Copyright tspringk ( http://wonderfl.net/user/tspringk )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dHUw
*/
package {
import flash.display.Graphics;
import flash.display.Shape;
import flash.events.Event;
import flash.filters.BlurFilter;
import flash.display.Sprite;
import flash.display.MovieClip;
public class Practice05 extends MovieClip {
private var initX:int = 0;
private var initY:int = 0;
private var initSize:int = 50;
private var nDegree:Number = 0;
private var nRadian:Number = 0;
private var nSpeed:Number = 5;
private var nDegreeToRadian:Number = Math.PI / 180;
private var nCenterX:Number = stage.stageWidth / 2;
private var nCenterY:Number = stage.stageHeight / 2;
private var nRadiusX:Number = 100;
private var nRadiusY:Number = 50;
private var nCos:Number = Math.cos(nRadian);
private var nSin:Number = Math.sin(nRadian);
public function Practice05() {
var ball:Shape = new Shape();
var ballG:Graphics = ball.graphics;
ballG.beginFill(0xffcc00, 1.0);
ballG.drawCircle ( initX, initY , initSize);
this.addChild(ball);
addEventListener(Event.ENTER_FRAME, xMoveX);
addEventListener(Event.ENTER_FRAME, xMoveY);
addEventListener(Event.ENTER_FRAME, xScale);
addEventListener(Event.ENTER_FRAME, xBlur);
addEventListener(Event.ENTER_FRAME, xUpdate);
}
private function xMoveX(eventObject:Event):void {
x = nCenterX + nCos * nRadiusX;
}
private function xMoveY(eventObject:Event):void {
y = nCenterY + nSin * nRadiusY;
}
private function xScale(eventObject:Event):void {
scaleX = scaleY = xGetIndexZ(0.8,1);
scaleX *= xGetIndexZ();
}
private function xBlur(eventObject:Event):void {
var nBlur:Number=xGetIndexZ(10,0);
var myBlur:BlurFilter=new BlurFilter(nBlur,nBlur/2);
filters=[myBlur];
}
private function xUpdate(eventObject:Event):void {
nDegree+=nSpeed;
nDegree = (nDegree%360+360)%360;
nRadian=nDegree*nDegreeToRadian;
nCos=Math.cos(nRadian);
nSin=Math.sin(nRadian);
}
private function xGetIndexZ(nMin:Number=-1, nMax:Number=1):Number {
var nIndexZ:Number = (nMax-nMin)*(nSin+1)/2+nMin;
return nIndexZ;
}
}
}