Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. Public Class Form1
  2. Private Angle As Single = 100
  3. Private NextIncrement As Single = 1
  4. Private Randomizer As New Random(Now.Millisecond)
  5. Private SliceColors As New List(Of Color)
  6. Private SlicesOnWheel As Integer = 6
  7. Private WheelRadius As Integer = 300
  8. Private WheelLocation As New Point(50, 50)
  9. Protected Overrides Sub OnPaint(e As PaintEventArgs)
  10. Dim g As Graphics = e.Graphics
  11. Dim x2, y2, d As Single
  12.  
  13. Dim theNumbers() As String = {"V", "I", "R", "T", "U", "S"}
  14. g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  15. g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
  16. g.Clear(Color.LightBlue)
  17. Dim sliceAngle As Single = CSng(360 / SlicesOnWheel)
  18. Dim rect As New Rectangle(WheelLocation, New Size(WheelRadius, WheelRadius))
  19. Dim r As Double = 0.495 * rect.Width
  20. Dim curveWidth As Integer = CInt(WheelRadius - (WheelRadius / (2.0! * 0.9)))
  21. Dim rect2 As New Rectangle(rect.Left + curveWidth, rect.Top + curveWidth, rect.Width - curveWidth * 2, rect.Height - curveWidth * 2)
  22. Dim count As Integer
  23. For I As Single = 0 To 359 Step sliceAngle
  24. g.FillPie(New SolidBrush(SliceColors(CInt(I / sliceAngle))), rect, I + NormalizeAngle(Angle), sliceAngle)
  25. g.DrawPie(Pens.White, rect, I + NormalizeAngle(Angle), sliceAngle)
  26.  
  27. g.FillPie(Brushes.AliceBlue, rect2, I + NormalizeAngle(Angle) + 1, sliceAngle - 2)
  28. g.DrawPie(Pens.Blue, rect2, I + NormalizeAngle(Angle) + 1, sliceAngle - 2)
  29.  
  30. d = I + NormalizeAngle(Angle)
  31. If theNumbers(count).ToString.Length = 1 Then d = d + sliceAngle / 2 ''se centra string en cuadro
  32. x2 = CInt((r * Math.Cos(d / 57.3)) + rect.X + rect.Width / 2)
  33. y2 = CInt((r * Math.Sin(d / 57.3)) + rect.Y + rect.Width / 2)
  34.  
  35. g.TranslateTransform(x2, y2)
  36. g.RotateTransform(d + 93)
  37.  
  38. g.DrawString(theNumbers(count).ToString, New Font("Arial", 12, FontStyle.Bold), Brushes.White, 0, 0)
  39. g.ResetTransform()
  40.  
  41. count += 1
  42. Next
  43. g.FillEllipse(Brushes.LightBlue, rect2)
  44. g.DrawEllipse(Pens.White, rect2)
  45. g.DrawEllipse(Pens.White, rect)
  46.  
  47. Dim Triangle() As Point = {New Point(400, 25), New Point(333, 108), New Point(427, 58)} '(horizontal,vertical)'
  48. g.DrawPolygon(Pens.Black, Triangle)
  49. g.FillPolygon(Brushes.Black, Triangle)
  50. MyBase.OnPaint(e)
  51. End Sub
  52. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  53. Me.DoubleBuffered = True
  54. Timer1.Interval = 15
  55. Dim numbers As New List(Of Integer) From {1, 2, 3, 4, 5, 6}
  56. SlicesOnWheel = numbers.Count
  57. Dim oddCount As Integer = 0
  58. Do
  59. SliceColors.Add(Color.Fuchsia)
  60. SliceColors.Add(Color.Orange)
  61. SliceColors.Add(Color.Red)
  62. SliceColors.Add(Color.Yellow)
  63. SliceColors.Add(Color.Green)
  64. SliceColors.Add(Color.Beige)
  65. Loop Until SliceColors.Count = numbers.Count
  66. End Sub
  67. Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  68. Angle = NormalizeAngle(Angle + NextIncrement)
  69. NextIncrement -= NextIncrement * 0.03!
  70. If NextIncrement <= 0.005 Then
  71. Timer1.Enabled = False
  72. End If
  73. Me.Text = Angle.ToString
  74. Me.Invalidate()
  75. End Sub
  76. Public Function NormalizeAngle(value As Single) As Single
  77. Return value Mod 360
  78. End Function
  79.  
  80. Private Sub btnSpin_Click_1(sender As Object, e As EventArgs) Handles btnSpin.Click
  81. If Timer1.Enabled = False Then
  82.  
  83. NextIncrement = Randomizer.Next(40, 75)
  84. End If
  85. Timer1.Enabled = Not Timer1.Enabled
  86. End Sub
  87. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement