fillCircle function
Draw and fill a circle into the image
with a center of x0
,y0
and the given radius
and color
.
The algorithm uses the same logic as drawCircle to calculate each point around the circle's circumference. Then it iterates through every point, finding the smallest and largest y-coordinate values for a given x- coordinate.
Once found, it draws a line connecting those two points. The circle is thus filled one vertical slice at a time (each slice being 1-pixel wide).
Implementation
Image fillCircle(Image image, int x0, int y0, int radius, int color) {
final points = _calculateCircumference(image, x0, y0, radius);
// sort points by x-coordinate and then by y-coordinate
points.sort((a, b) => (a.x == b.x) ? a.y.compareTo(b.y) : a.x.compareTo(b.x));
var start = points.first;
var end = points.first;
for (var pt in points.sublist(1)) {
if (pt.x == start.x) {
end = pt;
} else {
drawLine(image, start.xi, start.yi, end.xi, end.yi, color);
start = pt;
end = pt;
}
}
drawLine(image, start.xi, start.yi, end.xi, end.yi, color);
return image;
}