PDA

Click to See Complete Forum and Search --> : need help with filled circle


cyborg
May 30th, 2003, 05:23 PM
check this out...sometimes it draws where it shouldn't...

riis
May 31st, 2003, 10:55 AM
Hello,

I think this function should solve it:

Public Sub Glow(X As Single, Y As Single, Brightness As Double)
Dim xFrom As Single, xTo As Single, yFrom As Single, yTo As Single
Dim xx As Single, yy As Single, yDiff As Single
' TempRadius = Radius
' For TempRadius = 1 To Radius
' For Angle = 0 To PiTimes2 Step PiTimes2 / (TempRadius * 2 * Pi)
' BlendDIBPixel Round2(X + Sin(Angle) * TempRadius), Round2(Y + Cos(Angle) * TempRadius), 200, 100, 50, Brightness
' Next
' Next
yFrom = Y - Radius
yTo = Y + Radius

For yy = yFrom To yTo
yDiff = (yy - Y) / Radius
xTo = X + Sqr(1 - yDiff * yDiff) * Radius
xFrom = 2 * X - xTo
For xx = xFrom To xTo
BlendDIBPixel xx, yy, 200, 100, 50, Brightness
Next xx
Next yy

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...