Bitmap/Midpoint circle algorithm: Difference between revisions

Updated D entry
(Updated D entry)
(Updated D entry)
Line 304:
</pre>
=={{header|D}}==
Uses the secondbitmap Imagemodule implementationfrom the Bitmap Task.
<lang d>import bitmap2bitmap: ColorImage, ImageRGB;
 
void circle(Color)(Image!Color img, in int x0, in int y0, in int radius,
in int radius, in Color color) pure nothrow {
int f = 1 - radius;
int ddfX = 1;
Line 314:
int x = 0;
int y = radius;
img[x0, y0 + radius][x0] = color;
img[x0, y0 - radius][x0] = color;
img[y0][x0 + radius, y0] = color;
img[y0][x0 - radius, y0] = color;
 
while (x < y) {
Line 328:
ddfX += 2;
f += ddfX;
img[y0x0 + y][x0x, y0 + xy] = color;
img[y0 + y][x0 - x, y0 + y] = color;
img[y0 - y][x0 + x, y0 - y] = color;
img[y0x0 - y][x0x, y0 - xy] = color;
img[y0x0 + x][x0y, y0 + yx] = color;
img[y0 + x][x0 - y, y0 + x] = color;
img[y0 - x][x0 + y, y0 - x] = color;
img[y0x0 - x][x0y, y0 - yx] = color;
}
}
 
void main() {
auto img = new Image!RGB(25, 25);
img.clear(ColorRGB.white);
circle(img, 12, 12, 12, ColorRGB.black);
img.textualShow();
}</lang>