Drawing optimized filled circles on Agar surfaces
From Agar
This routine complements . It uses horizontal and vertical line drawing to fill the region. This method also utilizes an Optimized Integer Table Square Root Function.
/* * 8-way symmetric circle drawing (filled) * uses hline (above) * slightly inefficient (rewrites a couple of regions) * Public domain */ void circleFilled(AG_Surface *s, int xCenter, int yCenter, int radius, Uint32 c) { int x, y, r2; r2 = radius * radius; vline(s, xCenter, yCenter - radius, yCenter + radius, c); // hline(s, xCenter - radius, xCenter + radius, yCenter, c); y = radius; x = 1; y = (int) (sqrt(r2 - 1) + 0.5); while (x < y) { vline(s, xCenter + x, yCenter - y, yCenter + y, c); vline(s, xCenter - x, yCenter - y, yCenter + y, c); vline(s, xCenter + y, yCenter - x, yCenter + x, c); vline(s, xCenter - y, yCenter - x, yCenter + x, c); x += 1; y = (int) (sqrt(r2 - x*x) + 0.5); } if (x == y) { vline(s, xCenter + x, yCenter - y, yCenter + y, c); vline(s, xCenter - x, yCenter - y, yCenter + y, c); } }

