Results 1 to 2 of 2

Thread: need help with filled circle

  1. #1

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

    need help with filled circle

    check this out...sometimes it draws where it shouldn't...
    Attached Files Attached Files
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  2. #2
    Fanatic Member riis's Avatar
    Join Date
    Nov 2001
    Posts
    551
    Hello,

    I think this function should solve it:
    VB Code:
    1. Public Sub Glow(X As Single, Y As Single, Brightness As Double)
    2.   Dim xFrom As Single, xTo As Single, yFrom As Single, yTo As Single
    3.   Dim xx As Single, yy As Single, yDiff As Single
    4. '    TempRadius = Radius
    5. '    For TempRadius = 1 To Radius
    6. '        For Angle = 0 To PiTimes2 Step PiTimes2 / (TempRadius * 2 * Pi)
    7. '            BlendDIBPixel Round2(X + Sin(Angle) * TempRadius), Round2(Y + Cos(Angle) * TempRadius), 200, 100, 50, Brightness
    8. '        Next
    9. '    Next
    10.   yFrom = Y - Radius
    11.   yTo = Y + Radius
    12.  
    13.   For yy = yFrom To yTo
    14.     yDiff = (yy - Y) / Radius
    15.     xTo = X + Sqr(1 - yDiff * yDiff) * Radius
    16.     xFrom = 2 * X - xTo
    17.     For xx = xFrom To xTo
    18.       BlendDIBPixel xx, yy, 200, 100, 50, Brightness
    19.     Next xx
    20.   Next yy
    21.  
    22. End Sub

    The commented part is your function.
    There's one strange thing though: initially the circle is drawn as two half circles at the left and right edge. I didn't figure out yet why.

    While filling shapes, most algorithms are based on the idea that a shape is built of scanlines. Just color the pixels in the scanline which fall within the shape. (hence the for xx statement).

    Coincidentally or not: I'm busy with shape filling as well. They're just straight polygons (eventually with edges). I'm using a fill algorithm which keeps track of the collection of edges which together form the polygon. There's a slight rounding problem however. At one side there are blank pixels inside the polygon, and at the other side they are outside the polygon. I'm also drawing the outline, so it's quite disturbing if you want to do it really good...

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