Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Bitmap-Flood-fill/D/bitmap-flood-fill.d
Normal file
29
Task/Bitmap-Flood-fill/D/bitmap-flood-fill.d
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import std.array, bitmap;
|
||||
|
||||
void floodFill(Color)(Image!Color img, in uint x, in uint y,
|
||||
in Color color)
|
||||
/*pure*/ nothrow in {
|
||||
assert (y < img.ny && x < img.nx);
|
||||
} body {
|
||||
immutable target = img[x, y];
|
||||
static struct Pos { uint x, y; }
|
||||
auto stack = [Pos(x, y)];
|
||||
|
||||
while (!stack.empty) {
|
||||
immutable p = stack.back;
|
||||
stack.popBack;
|
||||
if (p.y < img.ny && p.x < img.nx && img[p.x, p.y] == target) {
|
||||
img[p.x, p.y] = color;
|
||||
stack.assumeSafeAppend;
|
||||
stack ~= [Pos(p.x, p.y + 1), Pos(p.x, p.y - 1),
|
||||
Pos(p.x + 1, p.y), Pos(p.x - 1, p.y)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
Image!RGB img;
|
||||
loadPPM6(img, "unfilled_circ.ppm");
|
||||
img.floodFill(200, 200, RGB(127, 0, 0));
|
||||
img.savePPM6("unfilled_circ_flooded.ppm");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue