home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH8 / SRC / FLAKEAN2.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-03-06  |  1.1 KB  |  47 lines

  1. Attribute VB_Name = "FlakeAni"
  2. Option Explicit
  3.  
  4. #If Win32 Then
  5.     Declare Function GetTickCount Lib "kernel32" () As Long
  6. #Else
  7.     Declare Function GetTickCount Lib "User" () As Long
  8. #End If
  9.  
  10. ' ************************************************
  11. ' Pause until GetTickCount shows the indicated
  12. ' time. This is accurate to within one clock tick
  13. ' (55 ms), not counting variability in DoEvents
  14. ' and Windows itself.
  15. ' ************************************************
  16. Sub WaitTill(next_time As Long)
  17.     Do
  18.         DoEvents
  19.     Loop While GetTickCount() < next_time
  20. End Sub
  21.  
  22. ' ************************************************
  23. ' Return the arc tangent of y/x taking into
  24. ' account the proper quadrant.
  25. ' ************************************************
  26. Function Arctan2(x As Single, y As Single)
  27. Const PI = 3.14159
  28. Const PI_OVER_2 = PI / 2
  29.  
  30. Dim theta As Single
  31.  
  32.     If x = 0 Then
  33.         If y > 0 Then
  34.             Arctan2 = PI_OVER_2
  35.         Else
  36.             Arctan2 = -PI_OVER_2
  37.         End If
  38.     Else
  39.         theta = Atn(y / x)
  40.         If x < 0 Then theta = PI + theta
  41.         Arctan2 = theta
  42.     End If
  43. End Function
  44.  
  45.  
  46.  
  47.