[Actionscript3] 纯文本查看 复制代码
package {
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite{
private var _con:Sprite;
private var _cir:Sprite = new Sprite();
private var _cirX:Number;
private var _cirY:Number;
private var _dx:Number;
private var _dy:Number;
private var _r:Number;
private var _n:Number;
private var angle_txt:TextField;
private var sin_txt:TextField;
private var cos_txt:TextField;
private var tan_txt:TextField;
public function Main() {
// constructor code
initView();
_con.addEventListener(MouseEvent.MOUSE_DOWN,drawCir);
_con.addEventListener(MouseEvent.MOUSE_UP,remove);
_con.addEventListener(MouseEvent.ROLL_OUT,remove);
}
private function initView():void{
_con = new Sprite;
_con.graphics.beginFill(0xcccccc);
_con.graphics.drawRect(-100,-100,200,200);
_con.graphics.endFill();
_con.graphics.lineStyle(1,0x333333);
_con.graphics.moveTo(-110,0);
_con.graphics.lineTo(110,0);
_con.graphics.lineTo(105,-3);
_con.graphics.moveTo(110,0);
_con.graphics.lineTo(105,4);
_con.graphics.moveTo(0,110);
_con.graphics.lineTo(0,-110);
_con.graphics.lineTo(-3,-105);
_con.graphics.moveTo(0,-110);
_con.graphics.lineTo(4,-105);
for(var i:int=0;i<11;i++){
if(i==5){
continue;
}
_con.graphics.moveTo(i*20-100,0);
_con.graphics.lineTo(i*20-100,-3);
_con.graphics.moveTo(0,i*20-100);
_con.graphics.lineTo(3,i*20-100);
}
_con.graphics.lineStyle(1,0xffffff);
for(var j:int=0;j<11;j++){
if(j==5){
continue;
}
_con.graphics.moveTo(j*20-100,-100);
_con.graphics.lineTo(j*20-100,100);
_con.graphics.moveTo(-100,j*20-100);
_con.graphics.lineTo(100,j*20-100);
}
angle_txt = new TextField();
sin_txt = new TextField();
cos_txt = new TextField();
tan_txt = new TextField();
angle_txt.autoSize = "left";
sin_txt.autoSize = "left";
cos_txt.autoSize = "left";
tan_txt.autoSize = "left";
_con.addChild(_cir);
addChild(sin_txt);
addChild(cos_txt);
addChild(angle_txt);
addChild(tan_txt);
angle_txt.x = 400;
angle_txt.y = 100;
sin_txt.x = 400;
sin_txt.y = 120;
cos_txt.x = 400;
cos_txt.y = 140;
tan_txt.x = 400;
tan_txt.y = 160;
addChild(_con);
_con.x = stage.stageWidth/2;
_con.y = stage.stageHeight/2;
}
private function zuobiao(evt:Event):void{
_cirX = mouseX-stage.stageWidth/2;
_cirY = mouseY-stage.stageHeight/2;
//trace(_cirX);
_cir.graphics.clear();
_cir.graphics.beginFill(0x000000);
_cir.graphics.drawCircle(_cirX,_cirY,2);
_cir.graphics.endFill();
_cir.graphics.lineStyle(1,0x0000ff);
_cir.graphics.moveTo(0,0);
_cir.graphics.lineTo(_cirX,_cirY);
_cir.graphics.moveTo(_cirX,_cirY);
_cir.graphics.lineTo(_cirX,0);
_n = Math.round(Math.atan2(-1*_cirY,_cirX)*180/Math.PI*100)/100;
if(_n<0){
_n+=360;
}
drawArc(_cir.graphics,10,0,_n);
angle_txt.text = "度数: " + _n;
sin_txt.text = "正弦: " + Math.round(Math.sin(_n/180*Math.PI)*100)/100;
cos_txt.text = "余弦: " + Math.round(Math.cos(_n/180*Math.PI)*100)/100;
if(_n == 90||_n == 270){
tan_txt.text = "正切: 无意义";
}else{
tan_txt.text = "正切: " + Math.round(Math.tan(_n/180*Math.PI)*100)/100;
}
}
private function drawCir(evt:MouseEvent):void{
this.addEventListener(Event.ENTER_FRAME,zuobiao);
}
private function remove(evt:MouseEvent):void{
this.removeEventListener(Event.ENTER_FRAME,zuobiao);
}
private function drawArc(g:Graphics,radius:Number,startAngle:Number,endAngle:Number):void{
for(var i:int=startAngle;i<=endAngle;i++){
var px:Number=radius*Math.cos(-i*Math.PI/180);
var py:Number=radius*Math.sin(-i*Math.PI/180);
if(i==startAngle)
g.moveTo(px,py);
g.lineTo(px,py);
}
}
}
}
[align=right]