|
|
Title | Draw a circle using Line statements |
Keywords | circle, drawing, line |
Categories | Graphics |
|
|
Once in a while, it's handy to be able to draw your own circles. For instance, if your drawing coordinate system is warped, this method lets you draw a circle that is appropriately warped.
Use Sin and Cos to calculate the points' positions. This is not the fastest possible method, but it's fast enough under most circumstances and much simpler than the faster algorithms.
Keep the number of segments relatively small or the circle gets kind of fuzzy and thick-looking.
|
|
Private Sub DrawCircle(ByVal obj As Object, ByVal cx As _
Single, ByVal cy As Single, ByVal radius As Single, _
ByVal num_segments As Integer)
Const PI = 3.14159265
Dim X As Single
Dim Y As Single
Dim theta As Single
Dim dtheta As Single
Dim seg As Integer
dtheta = 2 * PI / num_segments
obj.CurrentX = cx + radius
obj.CurrentY = cy
theta = 0
For seg = 1 To num_segments
theta = theta + dtheta
obj.Line -(cx + radius * Cos(theta), cy + radius * _
Sin(theta))
Next seg
End Sub
|
|
|
|
|
|