Math.atan2(y, x)

by ProjectNya
♥2 | Line 111 | Modified 2010-10-15 12:47:30 | MIT License
play

ActionScript3 source code

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

////////////////////////////////////////////////////////////////////////////////
// Math.atan2(y, x)
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var angle:Number;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            draw();
            angle = Math.atan2(4, 3)*180/Math.PI;
            var label:Label = new Label(400, 20, 14, Label.CENTER);
            label.x = 32;
            label.y = 400;
            addChild(label);
            label.textColor = 0x000000;
            label.text = "angle = Math.atan2(4, 3) = " + angle.toFixed(2);
        }
        private function draw():void {
            graphics.beginFill(0xFFFF00, 0.05);
            graphics.lineStyle(0, 0xFF0000);
            graphics.moveTo(50, 50);
            graphics.lineTo(50, 320);
            graphics.lineStyle(0, 0x0000FF);
            //graphics.moveTo(50, 320);
            graphics.lineTo(410, 320);
            graphics.lineStyle(0, 0x009900);
            //graphics.moveTo(410, 320);
            graphics.lineTo(50, 50);
            graphics.endFill();
            var labelA:Label = new Label(40, 20);
            labelA.x = 20;
            labelA.y = 20;
            addChild(labelA);
            labelA.textColor = 0x000000;
            labelA.text = "A (0, 0)";
            var labelB:Label = new Label(40, 20);
            labelB.x = 20;
            labelB.y = 330;
            addChild(labelB);
            labelB.textColor = 0x000000;
            labelB.text = "B (0, 3)";
            var labelC:Label = new Label(40, 20);
            labelC.x = 390;
            labelC.y = 330;
            addChild(labelC);
            labelC.textColor = 0x000000;
            labelC.text = "C (4, 3)";
            var labelAB:Label = new Label(40, 20);
            labelAB.x = 5;
            labelAB.y = 190;
            addChild(labelAB);
            labelAB.textColor = 0xFF0000;
            labelAB.text = "AB = 3";
            var labelBC:Label = new Label(40, 20);
            labelBC.x = 205;
            labelBC.y = 325;
            addChild(labelBC);
            labelBC.textColor = 0x0000FF;
            labelBC.text = "BC = 4";
            var txt:Label = new Label(40, 20);
            txt.x = 55;
            txt.y = 80;
            addChild(txt);
            txt.textColor = 0x000000;
            txt.text = "angle";
        }
        
    }

}


//////////////////////////////////////////////////
// Labelクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "_ゴシック";
    private var _width:uint = 20;
    private var _height:uint = 20;
    private var size:uint = 12;
    public static const LEFT:String = TextFormatAlign.LEFT;
    public static const CENTER:String = TextFormatAlign.CENTER;
    public static const RIGHT:String = TextFormatAlign.RIGHT;

    public function Label(w:uint, h:uint, s:uint = 12, align:String = LEFT) {
        _width = w;
        _height = h;
        size = s;
        draw(align);
    }

    private function draw(align:String):void {
        txt = new TextField();
        addChild(txt);
        txt.width = _width;
        txt.height = _height;
        txt.autoSize = align;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = size;
        tf.align = align;
        txt.defaultTextFormat = tf;
        textColor = 0x000000;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}