forked from: 三角関数

by nbhd
♥0 | Line 48 | Modified 2010-09-26 15:41:12 | MIT License
play

ActionScript3 source code

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

// forked from kotaro_tan's 三角関数
package
{
    import flash.geom.Point;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class Test extends Sprite
    { 
            private var _xx:Number;
            private var _yy:Number;
            private var _kakudo:int;
            private var _s:Sprite;
            private var _center:Point;
            
            private const RADIUS:int = 80;
            private const WIDTH:int = 10;
            private const HEIGHT:int = 10;
            private const THICKNESS7:int = 7;
            private const THICKNESS5:int = 5;
            
            public function Test()
            {
                addEventListener(Event.ADDED_TO_STAGE, _init);
            }
            
            private function _init(e:Event):void
            {
                removeEventListener(e.type, arguments.callee);
                
                _center = new Point(int(stage.stageWidth / 2), int(stage.stageHeight / 2));
                
                _s = addChild(new Sprite()) as Sprite;
                addEventListener(Event.ENTER_FRAME, _loop);
            }
            
            private function _loop(event:Event):void
            {
                _xx = Math.cos(Math.PI / 180 * _kakudo) * RADIUS;
                _yy = Math.sin(Math.PI / 180 * _kakudo) * RADIUS;
                
                _kakudo++;
                if (_kakudo > 360)
                {
                    _kakudo = 0;
                }
                
                var g:Graphics = _s.graphics;
                g.clear();
                g.beginFill(0x0, 1.0);
                g.lineStyle(THICKNESS7, 0x0);
                g.drawCircle(_center.x, _center.y, RADIUS);
                g.lineStyle(THICKNESS5, 0x0000FF);
                g.drawRect(_center.x + _xx - int(WIDTH / 2), _center.y + _yy - int(HEIGHT / 2), WIDTH, HEIGHT);
            }

    }
}