Posted By


Maverick_ex on 03/25/10

Tagged


Statistics


Viewed 140 times
Favorited by 1 user(s)

Trayectoria curva


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //Función valor absoluto
  2. function abs( value:Number ):Number
  3. {
  4. return value < 0 ? -value : value;
  5. }
  6.  
  7. //Funcion que se ejecuta cuando se pulsa el botón del ratón
  8. function drag(event:MouseEvent):void {
  9. leyenda.visible=false;
  10. letrero.visible = false;
  11. event.currentTarget.startDrag();
  12. centro.visible = true;
  13. destino.addEventListener(MouseEvent.MOUSE_MOVE, updateAfterEvent);
  14. }
  15.  
  16. //Funcion que se ejecuta cuando se dejde pulsar el botón del ratón
  17. function drop(event:MouseEvent):void {
  18. event.currentTarget.stopDrag();
  19. leyenda.visible=true;
  20. destino.removeEventListener(MouseEvent.MOUSE_MOVE, updateAfterEvent);
  21. actualizarPunto();
  22. dibujarCirculo();
  23. }
  24.  
  25. //Funcion que se ejecuta cuando se pulsa el botón del ratón y se mueve
  26. function updateAfterEvent(event:MouseEvent):void{
  27. actualizarPunto();
  28. dibujarCirculo();
  29. textoCentro.text = "Centro: (0, "+centroY.toFixed(0)+")";
  30. textoAngulo.text = "Angulo de giro: "+angulo.toFixed(1);
  31. }
  32.  
  33. //Dibuja el circulo
  34. function dibujarCirculo(){
  35. mc.graphics.clear();
  36. mc.graphics.lineStyle(1,0xFFFFFF);
  37. mc.graphics.drawCircle(centroY*-1+250,150,radio);
  38. }
  39.  
  40. //Calcula posición del centro y el ángulo de giro
  41. function actualizarPunto(){
  42. pX = 150-destino.y;
  43. pY = (destino.x-250)*-1;
  44. texto.text = "Destino: ("+pX.toFixed(0)+", "+pY.toFixed(0)+")";
  45.  
  46. if (pX!=0){
  47. centroY = (pX*pX+pY*pY)/(2*pY);
  48. }else{
  49. centroY = 0;
  50. }
  51.  
  52. sacaAngulo();
  53.  
  54. centro.x=centroY*-1+250;
  55. centro.y = 150;
  56. radio = abs(centroY);
  57. }
  58.  
  59. function sacaAngulo(){
  60. var destY:Number= pY-centroY;
  61.  
  62. angulo = (Math.atan(destY/pX))*(180/Math.PI);
  63.  
  64. //Primer y segundo cuadrante
  65. if (pX>=0 && pY<0)
  66. angulo=angulo+360;
  67. //Segundo cuadrante
  68. else if (y>0)
  69. angulo=angulo+180;
  70. else
  71. angulo=angulo+180;
  72.  
  73. if(pY==0){
  74. angulo=5;
  75. }else if(pY>0){
  76. angulo+=90;
  77. }else{
  78. angulo=360-angulo+90;
  79. }
  80. }
  81.  
  82. destino.addEventListener(MouseEvent.MOUSE_DOWN, drag);
  83. destino.addEventListener(MouseEvent.MOUSE_UP, drop);
  84.  
  85. var angulo:Number = 0;
  86. var pX:Number = 150-destino.y;
  87. var pY:Number = (destino.x-250)*-1;
  88. var mc:MovieClip = new MovieClip();
  89. var centroY:Number = 0;
  90. var radio:Number = 0;
  91. centro.visible = false;
  92. leyenda.visible = false;
  93. texto.mouseEnabled = false;
  94. textoCentro.mouseEnabled = false;
  95. textoAngulo.mouseEnabled = false;
  96. destino.buttonMode = true;
  97. actualizarPunto();
  98. dibujarCirculo();
  99. this.addChildAt(mc, 0);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.