Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleDraw a circle using Line statements
Keywordscircle, drawing, line
CategoriesGraphics
 
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
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated