|
-
Oct 1st, 2002, 05:51 PM
#1
Thread Starter
New Member
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!
-
Oct 1st, 2002, 10:33 PM
#2
Addicted Member
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
-
Oct 6th, 2002, 02:59 AM
#3
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
-
Oct 7th, 2002, 01:03 PM
#4
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|