Results 1 to 4 of 4

Thread: midpoint circle drawing

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    8

    midpoint circle drawing

    Hi,

    i am having trouble getting my circle centered. When i run my program it draws the circle waaay in the upper left hand corner of my window so i can't even see a circle.

    How can i get it to draw around a specified origin? I have this so far.

    i have a feeling the circle is being draw outside my field of view. But how can i get it so the center of the circle is somewhere on the form where i can see the whole circle?

    I am using the midpoint circle algorithm.



    Code:
    Option Explicit
    Dim radius As Integer
    Dim midpoint As Integer
    Dim x, y, d As Integer
    
    Private Sub cmdDrawCircle_Click()
        radius = InputBox("Please enter the radius of the circle")
        Call MidPointcircle
        
    End Sub
    
    Private Sub CirclePoints()
        PSet (x, y)
        PSet (y, x)
        PSet (y, -x)
        PSet (x, -y)
        PSet (-x, -y)
        PSet (-y, -x)
        PSet (-y, x)
        PSet (-x, y)
    End Sub
    
    Private Sub MidPointcircle()
        
        
        x = 0
        y = radius
        d = 1 - radius
        Call CirclePoints
        Do While y > x
            If d < 0 Then
                d = d + x * 2 + 3
                x = x + 1
            Else
                d = d + (x - y) * 2 + 5
                x = x + 1
                y = y - 1
                
            End If
        Call CirclePoints
        Loop
        
        
    End Sub
    
    Private Sub Form_Load()
        DrawWidth = 1
    End Sub
    thanks!

  2. #2
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi,
    Usually you must provide some sort of offset for the center of the circle to be drawn. The fact that it is in the top-left corner (probably showing only 1/4 of a circle).

    Do something like this.

    Code:
    'these will represent the X and Y offsets
    DIM mnScreenOffsetX AS LONG
    DIM mnScreenOffsetY AS LONG
    
    'assuming you are drawing to form1
    mnScreenOffsetX = form1.width / 2
    mnScreenOffsetY = form1.height / 2
    
    'now, the above points should represent the center of your form
    'To draw a simple circle in the middle, you could do something like 
    'this.
    form1.circle (mnScreenOffsetX, mnScreenOffsetY), fRadius, nColor

    In your example, let's take one PSET...

    PSet (x, y)

    Modify it to read PSet (mnScreenOffsetX + x, mnScreenOffsetY + y)

    Hope this helps.
    Regards,
    ChuckB

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Ah,

    a drawing problem. I had this. But it is because u need to do one more line of code.

    Me.Show


    That is probably all u needed to do. Just use things like this for it to be easier;

    Private Sub DrawCircle_Click()
    Dim radius As Integer
    radius = InputBox("Please Enter the radius of the circle")
    Me.Show
    Me.CurrentX = 1300 'The horizontal coordinate of the form
    Me.CurrentY = 1300 'The vertical coordinate of the form
    Me.Circle (Me.CurrentX, Me.CurrentY), radius
    End Sub

    Hope this helped

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4
    Addicted Member
    Join Date
    Aug 2002
    Posts
    192
    Scale(-100, 100) - (-100, 100)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width