円運動
forked from forked from: forked from: flash on 2010-5-2 (diff: 16)
ActionScript3 source code
/**
* Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lhrL
*/
// forked from hacker_szoe51ih's forked from: forked from: flash on 2010-5-2
// forked from hacker_szoe51ih's forked from: flash on 2010-5-2
// forked from hacker_szoe51ih's flash on 2010-5-2
package {
import flash.display.*;
import flash.events.*;
[SWF(backgroundColor="#dddddd", width="500", height="500", frameRate="30")]
public class FlashTest extends Sprite {
public var rot:Number;
public var hankei:Number;
public var centerX:Number;
public var centerY:Number;
public var ball:Sprite;
public function FlashTest() {
stage.quality=StageQuality.HIGH;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
hankei=100;
rot=0;
centerX=this.stage.stageWidth/2-100;
centerY=this.stage.stageHeight/2-100;
//ボールを作る
ball=new Sprite();
ball.graphics.beginFill(0x000000);
ball.graphics.drawCircle(100,100,10);
ball.graphics.endFill();
addChild(ball);
ball.x=this.stage.stageWidth/2;
ball.y=this.stage.stageHeight/2;
this.addEventListener(Event.ENTER_FRAME,loop);
}
public function loop(e:Event):void{
rot += 10;
ball.x=centerX+hankei*Math.cos(rot*Math.PI/180);
//一般の数学だと反時計回りになるが、flashでは下に行くほどYの値が大きくなるから時計回りになる
ball.y=centerY+hankei*Math.sin(rot*Math.PI/180);
if(rot>360){
rot %= 2*Math.PI;
}
}
}
}
