Results 1 to 7 of 7

Thread: Filled circle with exact pixel count

  1. #1

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755

    Filled circle with exact pixel count

    hi!
    i've got a code for drawing a circle:

    VB Code:
    1. For Angle = 0 To 360 Step 1 / 100
    2.     SetPixelV Picture1.hdc, Round(CenterX + Cos((Angle * (3.1415926 / 180))) * Radius), Round(CenterY + Sin((Angle * (3.1415926 / 180))) * Radius), RGB(0, 255, 0)
    3. Next Angle

    but now i want to fill it using setpixelv but how?
    if i do for i = 0 to radius, it draws too many or too few times at each pixel...so i have to change the step.

    is there any way to know exactly how many pixels that will be used, or do i have to do this another way?
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    It's easy. Create a reverse of the angle (360 - Angle) and use Cos() on both of them. Then, you have the left position and right position. Set your pixels from the left to the right (I think its AngRev to Angle) and use Sin(Angle) as the Y value.

    It should work.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    ok! thanks!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    heres the new code:

    VB Code:
    1. For X = Round(CenterX + Cos(((360 - Angle) * (3.1415926 / 180))) * Radius) To Round(CenterX + Cos((Angle * (3.1415926 / 180))) * Radius)
    2.             For Y = Round(CenterY + Sin(((360 - Angle) * (3.1415926 / 180))) * Radius) To Round(CenterY + Sin((Angle * (3.1415926 / 180))) * Radius)
    3.                 SetPixelV Picture1.hdc, X, Y, vbRed
    4.             Next Y
    5.         Next X

    theres only one thing wrong with this....it draws a line across each time, and that makes is draw over some pixels alredy drawn...
    the main reason i wanted to do this was to take the average color of every pixel and the paint color, so the new color was half transparent...
    but if it draws too many times on some pixels, so the new color is not the average...
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  5. #5

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    oh!
    i used the same x value for every pixel and it looked ok!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  6. #6

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    oh....i missed some things...
    it was not right!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  7. #7

    Thread Starter
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    fixed some things!
    works perfect now!
    thanks for your help!
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

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