回転方法(2)

by _wonder forked from 回転方法(1) (diff: 13)
♥0 | Line 43 | Modified 2010-05-31 18:20:27 | MIT License
play

ActionScript3 source code

/**
 * Copyright _wonder ( http://wonderfl.net/user/_wonder )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9Eug
 */

// forked from _wonder's 回転方法(1)
// forked from _wonder's base
package {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class Rotate extends Sprite {
    		private var ball:Ball;
    		private var vr:Number = 0.05;
    		private var cos:Number = Math.cos(vr);
    		private var sin:Number = Math.sin(vr);
    		
    		public function Rotate() {
            init();
        }
        
        private function init():void {
        		ball = new Ball();
        		ball.x = 100;
        		ball.y = 100;
        		addChild( ball );
        		addEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void{
        		var x1:Number = ball.x - stage.stageWidth / 2;
        		var y1:Number = ball.y - stage.stageHeight / 2;
        		var x2:Number = cos * x1 - sin * y1;
        		var y2:Number = cos * y1 + sin * x1;
        		ball.x = stage.stageWidth / 2 + x2;
        		ball.y = stage.stageHeight / 2 + y2;
        }
    }
}

import flash.display.Sprite;

class Ball extends Sprite {
	public var radius:Number;
	public var color:uint;
	
	public function Ball(radius:Number=40, color:uint=0Xff0000){
		this.radius = radius;
		this.color = color;
		init();
	}
	
	public function init():void {
		graphics.beginFill(color);
		graphics.drawCircle(0, 0, radius);
		graphics.endFill();
	}
}

Forked