I'm using the following algorithm to plot a filled circle. However, it generates duplicate points and I'm not sure where I'm going wrong.
Any advice appreciated.
def get_filled_circle(radius):
d = (5 - radius * 4) / 4.0
x = 0
y = radius
points = []
while True:
for idx in range(-x, x+1, 1):
points.append((idx, y))
if y != 0:
points.append((idx,-y))
for idx in range(-y, y+1, 1):
points.append((idx, x))
if x != 0:
points.append((idx,-x))
if (d < 0):
d += 2 * x + 1
else:
d += 2 * (x - y) + 1
y -= 1
x += 1
if (y < x):
break
return points
The output below shows the plotted points, where "!" indicates a duplicate:
*!!!*
!!!!!!!!!
*********
***********
***********
***********
***********
***********
*********
!!!!!!!!!
*!!!*