|
-
Oct 26th, 2002, 07:36 PM
#1
Thread Starter
Junior Member
Print circle one pixel at a time
I know the syntax for a circle which prints it on the screen instantly, but I would like to print a circle (of a given size and placement) one point or pixel at a time so you could see the circle being drawn. Then I could move an object around in a circle. How can I do this?
Sparky84
-
Oct 26th, 2002, 08:23 PM
#2
Lively Member
Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
As for the coords to use, I dont remember the exact equation, you might look for it on google, or just dig up an old geomtry book
-
Oct 26th, 2002, 10:12 PM
#3
Good Ol' Platypus
VB Code:
Radian = Angle * (3.1415926 / 180)
PixelX = CentreX + Cos(Radian) * Radius
PixelY = CentreY + Sin(Radian) * Radius
Remember, if you're going to be dealing natively in radians, you'll want to remove the first line.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Oct 27th, 2002, 09:07 AM
#4
Thread Starter
Junior Member
I appreciate the 2 replies, but I can not print the circle one dot at a time with the declare or code shown to me - it didn't do anything. I would need the code that could make it work - do I need to dim anything - do I use PSet - I would need all the code and know just how to do it.
Sparky84
-
Oct 27th, 2002, 12:20 PM
#5
Good Ol' Platypus
Well, do a loop with my code, with Angle being 0 to 359, maybe step .5 if you want to do it a bit more smoothly. Then use PSET with whatever colour you want, and PixelX and PixelY being the X and Y values.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Oct 27th, 2002, 03:49 PM
#6
Thread Starter
Junior Member
To draw the circle slowly what I have so far is:
Dim Radian As Double, PixelX As Single, PixelY As Single, Angle As Single
Under MouseDown to activate it I have - For Angle = 0 To 359 Step 0.5
Radian = Angle * (3.1415926 / 180)
PixelX = CentreX + Cos(Radian) * Radius
PixelY = CentreY + Cos(Radian) * Radius
PSet (PixelX, PixelY)
Next Angle
In Form Load I have
CentreX = 100
CentreY = 100
I did this to get it away from the side.
All it does is print one dot in the upper - left of the form.
Still hoping to learn how to make this work.
Sparky84
-
Oct 27th, 2002, 03:55 PM
#7
Good Ol' Platypus
Here you go:
VB Code:
Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Sub Form_MouseDown(...)
Dim Radian As Double, PixelX As Single, PixelY As Single, Angle As Double
For Angle = 0 To 359.5 Step 0.5
Radian = Angle * (3.1415926 / 180)
PixelX = CentreX + Cos(Radian) * Radius
PixelY = CentreY + Sin(Radian) * Radius
SetPixelV Picture1.hDC, PixelX, PixelY, RGB(0, 0, 0)
Next Angle
End Sub
Private Sub Form_Load()
CentreX = 100
CentreY = 100
Radius = 50
End Sub
I think that will work. Look at what I've changed, it'll help you to figure out where you went wrong.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
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
|