본문 바로가기

AS3/ActionScript

사인/코사인을 이용한 원그리기

package {
    
    import flash.display.Sprite;
    import ascb.units.Converter;
    import ascb.units.Unit;
    import flash.events.Event;
    
    public class NumbersAndMath2 extends Sprite {
        
        private var _square:Sprite;
        private var _angle:uint;
        private var _sprite:Sprite;
        
        public function NumbersAndMath2() {
            _sprite = new Sprite();
              addChild( _sprite );
              _sprite.graphics.beginFill( 0xffffff );
             _sprite.graphics.drawRect( 0, 0, 400, 400 );
              _sprite.graphics.endFill();
            addEventListener( Event.ENTER_FRAME, move );
            
            _square = new Sprite();
            _square.graphics.lineStyle(0);
            _square.graphics.drawCircle( 0, 0, 20);
            addChild( _square );
            _angle = 0;
            _square.graphics.endFill();
        }
        
        private function move( event:Event ):void {
            var converter:Converter = Unit.DEGREE.getConverterTo( Unit.RADIAN );
            var angleRadians:Number = converter.convert( _angle );
            _square.x = Math.cos( angleRadians ) * 100 + 200;
            _square.y = Math.sin( angleRadians ) * 100 + 200;
            _angle++;
            _sprite.graphics.lineStyle( 1, 0, 1 );
            _sprite.graphics.lineTo( _square.x, _square.y );
            
        }
        
    }
}