サイン波の軌跡

by hacker_szoe51ih forked from 円運動 (diff: 9)
♥0 | Line 40 | Modified 2010-09-03 00:45:32 | MIT License
play

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/nhsl
 */

// forked from hacker_szoe51ih's 円運動
// 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(0,0,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+=10;
            ball.y=centerY+90+hankei*Math.sin(rot*Math.PI/180);      
            if(rot>360){
                   rot %= 2*Math.PI;
            }
            if(ball.x>465){
                  ball.x=0;
            }

        }
        
        
    }
}