Results 1 to 7 of 7

Thread: Print circle one pixel at a time

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    Aurora, CO
    Posts
    16

    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

  2. #2
    Lively Member FireSlash518's Avatar
    Join Date
    Nov 2001
    Posts
    67
    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

    Leader of the Maxoverkill Mods
    -Fire§lash

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    VB Code:
    1. Radian = Angle * (3.1415926 / 180)
    2. PixelX = CentreX + Cos(Radian) * Radius
    3. 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)

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    Aurora, CO
    Posts
    16
    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

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    Aurora, CO
    Posts
    16
    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

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Here you go:
    VB Code:
    1. 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
    2.  
    3. Private Sub Form_MouseDown(...)
    4. Dim Radian As Double, PixelX As Single, PixelY As Single, Angle As Double
    5.  
    6. For Angle = 0 To 359.5 Step 0.5
    7.     Radian = Angle * (3.1415926 / 180)
    8.     PixelX = CentreX + Cos(Radian) * Radius
    9.     PixelY = CentreY + Sin(Radian) * Radius
    10.     SetPixelV Picture1.hDC, PixelX, PixelY, RGB(0, 0, 0)
    11. Next Angle
    12.  
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16.     CentreX = 100
    17.     CentreY = 100
    18.     Radius = 50
    19. 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
  •  



Click Here to Expand Forum to Full Width