1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Point;
[SWF( width = '1024', height = '500', backgroundColor = '0xdcdcdc')]
public class Main extends Sprite
{
private const R:uint = 240;
private var angle:Number = 0;
private var pt:Point;
private var oldtheta:Number = 0;
private var Rapporteur:Sprite = new Sprite();
private var infoangle:TextField = new TextField();
private var police:TextFormat = new TextFormat();
public function Main():void{
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void{
const pi:Number = Math.PI;
const l:Number = 1.95 * R / 2;
const d:Number = 1.8 * R / 2;
removeEventListener(Event.ADDED_TO_STAGE, init);
x =2* R;
y = stage.stageHeight / 2;
with (graphics) {
lineStyle(1, 0);
moveTo(R,0);
lineTo(1.3*R,0);
}
with (Rapporteur.graphics){
beginFill(0xFFFFFF);
drawCircle(0, 0, R);
endFill();
lineStyle(2, 0);
drawCircle(0, 0,0.01*R);
moveTo(R, 0);
lineTo(R - 0.3 * l, 0);
for (var i:uint = 0; i < 360; i++){
moveTo(R * Math.cos(i * pi / 180), R * Math.sin(i * pi / 180));
lineTo(l * Math.cos(i * pi / 180), l * Math.sin(i * pi / 180));
}
for (var j:uint = 0; j < 36; j++){
moveTo(R * Math.cos(10 * j * pi / 180), R * Math.sin(10 * j * pi / 180));
lineTo(d * Math.cos(10 * j * pi / 180), d * Math.sin(10 * j * pi / 180));
}
}
with (police){
font = "Tahoma";
size = 14;
bold = true;
color = 0;
}
with (infoangle){
x = 1.1*R;
y = 50;
defaultTextFormat = police;
text = String(angle);//en degrés
}
Rapporteur.buttonMode = true;
addChild(Rapporteur);
addChild(infoangle);
Rapporteur.addEventListener(MouseEvent.MOUSE_DOWN, dodown);
stage.addEventListener(MouseEvent.MOUSE_UP, doup);
}
private function doup(e:MouseEvent):void{
Rapporteur.removeEventListener(MouseEvent.MOUSE_MOVE, domove);
}
private function domove(e:MouseEvent):void{
var dtheta:Number;
pt = new Point(mouseX, mouseY);
dtheta = Math.atan2(pt.y, pt.x) * 180 / Math.PI;
Rapporteur.rotationZ += dtheta - oldtheta;
angle = (Rapporteur.rotationZ % 360);
oldtheta = dtheta;
infoangle.text = String(angle);
}
private function dodown(e:MouseEvent):void{
pt = new Point(mouseX, mouseY);
oldtheta = Math.atan2(pt.y, pt.x) * 180 / Math.PI;
Rapporteur.addEventListener(MouseEvent.MOUSE_MOVE, domove);
}
}
} |
Partager