home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch06 / spiral1 / spiral.bas next >
Encoding:
BASIC Source File  |  1996-03-03  |  1.2 KB  |  49 lines

  1. Attribute VB_Name = "SpiralMod"
  2. Global BreakNow As Integer
  3. Global PenColor As Long
  4.  
  5. Sub DrawRoullette()
  6. Dim R1 As Integer, R2 As Integer
  7. Dim r As Single
  8. Dim pi As Double
  9.  
  10. R1 = Form1.HScroll1.Value
  11. R2 = Form1.HScroll2.Value - 80
  12. If R2 = 0 Then R2 = 10
  13. r = Form1.HScroll4.Value
  14. pi = 4 * Atn(1)
  15.  
  16. Dim loop1 As Integer, loop2 As Single
  17. Dim t As Double, X As Double, Y As Double
  18. Dim Rotations As Integer
  19.  
  20. If Int(R1 / R2) = R1 / R2 Then
  21.     Rotations = 1
  22. Else
  23.     Rotations = Abs(R2 / 10)
  24.     If Int(R2 / 10) <> R2 / 10 Then Rotations = 10 * Rotations
  25. End If
  26.  
  27. For loop1 = 1 To Rotations
  28.     If BreakNow Then
  29.         Form1.Command1.Caption = "Start"
  30.         BreakNow = False
  31.         Exit Sub
  32.     End If
  33.     
  34.     For loop2 = 0 To 2 * pi Step pi / (4 * 360)
  35.         t = loop1 * 2 * pi + loop2
  36.         X = (R1 + R2) * Cos(t) - (R2 + r) * Cos(((R1 + R2) / R2) * t)
  37.         Y = (R1 + R2) * Sin(t) - (R2 + r) * Sin(((R1 + R2) / R2) * t)
  38.         Form1.Picture1.PSet (Form1.Picture1.ScaleWidth / 2 + X, Form1.Picture1.ScaleHeight / 2 + Y), PenColor
  39.         Form1.Picture2.PSet (Form1.Picture1.ScaleWidth / 2 + X, Form1.Picture1.ScaleHeight / 2 + Y), PenColor
  40.     Next
  41.     DoEvents
  42. Next
  43. Form1.Command1.Caption = "Start"
  44. BreakNow = False
  45.  
  46. End Sub
  47.  
  48.  
  49.