Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.09 KB | None | 0 0
  1. #include <GUIConstantsEx.au3>
  2. #include <StaticConstants.au3>
  3. #include <WindowsConstants.au3>
  4. #include <GDIPlus.au3>
  5. #include "GWCAConstants.au3"
  6. Opt("MouseCoordMode", 2)
  7. #region ### START Koda GUI section ### Form=
  8. $Form1 = GUICreate("Form1", 800, 800)
  9. GUISetState(@SW_SHOW)
  10. #endregion ### END Koda GUI section ###
  11. Global $ThetaDeg
  12.  
  13. _GDIPlus_Startup()
  14. $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1)
  15.  
  16. while 1
  17. _GDIPlus_GraphicsDrawEllipse($hGraphic, 195, 330, 210, 210)
  18. _GDIPlus_GraphicsDrawRect($hGraphic, 300, 435, 2, 2)
  19. $cbType = "float"
  20. $distance = CmdCB($CA_GetMyDistanceToAgent, 1)
  21. sleep(50)
  22. $owncoords = CmdCB($CA_Getcoords, -2)
  23. sleep(50)
  24. $targetcoords = CmdCB($CA_Getcoords, -1)
  25. sleep(50)
  26. $angle =-1 * ATan2($owncoords[1] - $targetcoords[1], $owncoords[0] - $targetcoords[0])
  27. $x = 300 + $distance[0] * Cos($angle)
  28. $y = 435 + $distance[0] * Sin($angle)
  29.  
  30. _GDIPlus_GraphicsDrawRect($hGraphic, $x, $y, 2, 2)
  31. wend
  32.  
  33. Func atan2($x, $y)
  34.     $Pi = 4 * ATan(1)
  35.     If StringIsInt($x) Or StringIsFloat($x) Then
  36.         If StringIsInt($y) Or StringIsFloat($y) Then
  37.             ; OK
  38.         Else
  39.             SetError(1)
  40.             Return ""
  41.         EndIf
  42.     Else
  43.         SetError(1)
  44.         Return ""
  45.     EndIf
  46.     Dim $PolarAnswer[3] ; $Results[0]=Radius, [1]=Theta (in Radians), [2]=Theta (in Degrees)
  47.     $r = Sqrt(($x ^ 2) + ($y ^ 2))
  48.     $PolarAnswer[0] = $r
  49.     Select
  50.         Case $x = 0 And $y = 0
  51.             $ThetaRad = 0
  52.             $ThetaDeg = 0
  53.         Case $x >= 0 And $y >= 0 ; +x/+y = 0-90deg quadrant
  54.             $ThetaRad = ATan($x / $y)
  55.             $ThetaDeg = $ThetaRad * 180 / $Pi
  56.         Case $x >= 0 And $y < 0 ; +x/-y = 90-180deg quadrant
  57.             $ThetaRad = ATan(Abs($y) / $x)
  58.             $ThetaDeg = $ThetaRad * 180 / $Pi + 90
  59.             $ThetaRad = $ThetaRad + $Pi / 2
  60.         Case $x < 0 And $y < 0 ; -x/-y = 180-270deg quadrant
  61.             $ThetaRad = ATan(Abs($x) / Abs($y))
  62.             $ThetaDeg = $ThetaRad * 180 / $Pi + 180
  63.             $ThetaRad = $ThetaRad + $Pi
  64.         Case $x < 0 And $y >= 0 ; -x/+y = 2700-360deg quadrant
  65.             $ThetaRad = ATan($y / Abs($x))
  66.             $ThetaDeg = $ThetaRad * 180 / $Pi + 270
  67.             $ThetaRad = $ThetaRad + 3 * $Pi / 2
  68.     EndSelect
  69.     $PolarAnswer[2] = $ThetaDeg
  70.     SetError(0)
  71.     Return $ThetaDeg
  72. EndFunc   ;==>atan2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement