Reputation: 31
i was trying to write a program that draws circles around the center of the form (creating a larger circle) and i noticed that it isn't really working, the circles are in the wrong coordinates, the following pictures explain what i mean
when the input is 3:
when the input is 10:
as you see, the circles aren't uniformed, here is the code:
Dim center As Integer = Convert.ToInt32(Me.Width / 2)
Dim angels As Integer = 360 / deviceCount
TextBox1.Text = deviceCount
Dim i As Integer
For i = 1 To deviceCount
e.Graphics.DrawEllipse(Pens.Red, Convert.ToInt32(center + 275 * Math.Cos(i * angels)) - 25, Convert.ToInt32(center + 275 * Math.Sin(i * angels)) - 25, 50, 50)
Next
*note: the form is 600*600 and deviceCount is the number in the textbox (the number of circles)
thanks in advance!
Edit:
Upvotes: 1
Views: 669
Reputation: 78155
The lazy way.
Private Sub DrawCircles(ByVal Graphics As Graphics, ByVal Number As Integer, ByVal Radius As Integer)
Dim Center = New Point(Me.ClientSize.Width \ 2, Me.ClientSize.Height \ 2)
Dim BigRadius = Math.Min(Center.X, Center.Y) - Radius
Dim CurrentState = Graphics.Save()
Graphics.ResetTransform()
Graphics.TranslateTransform(Center.X, Center.Y)
Graphics.DrawEllipse(Pens.Blue, -BigRadius, -BigRadius, BigRadius * 2, BigRadius * 2)
For i As Integer = 1 To Number
Graphics.RotateTransform(360 \ Number)
Graphics.DrawEllipse(Pens.Red, 0, -BigRadius - Radius, Radius * 2, Radius * 2)
Next
Graphics.Restore(CurrentState)
End Sub
Upvotes: 3