Bitmap/Midpoint circle algorithm: Difference between revisions

Updated D entry
(Updated D entry)
Line 305:
=={{header|D}}==
Uses the second Image implementation.
<lang d>import imagebitmap2: Color, Image;
 
void circle(Image img, in int x0, in int y0, in int radius, Color color=Color.white) {
in Color color) pure nothrow {
int f = 1 - radius;
int ddf_xddfX = 1;
int ddf_yddfY = -2 * radius;
int x = 0;
int y = radius;
Line 321 ⟶ 322:
if (f >= 0) {
y--;
ddf_yddfY += 2;
f += ddf_yddfY;
}
x++;
ddf_xddfX += 2;
f += ddf_xddfX;
img[y0 + y][x0 + x] = color;
img[y0 + y][x0 - x] = color;
Line 340 ⟶ 341:
void main() {
auto img = new Image(25, 25);
circle(img, 12, 12, 12.clear(Color.white);
circle(img, 12, 12, 12, Color.textView(black);
img.textualShow();
}</lang>
{{out}}
Output:
<pre>.........#######.........
.......##.......##.......