March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -2,7 +2,7 @@ import std.array, bitmap;
|
|||
|
||||
void floodFill(Color)(Image!Color img, in uint x, in uint y,
|
||||
in Color color)
|
||||
/*pure nothrow*/ in {
|
||||
pure nothrow in {
|
||||
assert (y < img.ny && x < img.nx);
|
||||
} body {
|
||||
immutable target = img[x, y];
|
||||
|
|
@ -11,21 +11,18 @@ void floodFill(Color)(Image!Color img, in uint x, in uint y,
|
|||
|
||||
while (!stack.empty) {
|
||||
immutable p = stack.back;
|
||||
stack.popBack();
|
||||
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(); // Not pure nor nothrow.
|
||||
stack ~= Pos(p.x - 1, p.y);
|
||||
stack ~= Pos(p.x + 1, p.y);
|
||||
stack ~= Pos(p.x, p.y - 1);
|
||||
stack ~= Pos(p.x, p.y + 1);
|
||||
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() {
|
||||
auto img = new Image!RGB();
|
||||
img.loadPPM6("Unfilledcirc.ppm");
|
||||
auto img = loadPPM6(null, "unfilled_circ.ppm");
|
||||
img.floodFill(200, 200, RGB(127, 0, 0));
|
||||
img.savePPM6("Unfilledcirc_flooded.ppm");
|
||||
img.savePPM6("unfilled_circ_flooded.ppm");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'white blue yellow black orange red'=: 255 255 255,0 0 255,255 255 0,0 0 0,255 165 0,:255 0 0
|
||||
myimg=: white makeRGB 50 70
|
||||
lines=: (_2]\^:2) 0 0 25 0 , 25 0 25 35 , 25 35 0 35 , 0 35 0 0
|
||||
lines=: _2]\^:2 ] 0 0 25 0 , 25 0 25 35 , 25 35 0 35 , 0 35 0 0
|
||||
myimg=: (lines;blue) drawLines myimg
|
||||
myimg=: (3 3; yellow) floodFill myimg
|
||||
myimg=: ((35 25 24 ,: 35 25 10);black) drawCircles myimg
|
||||
myimg=: ((25 35 24 ,: 25 35 10);black) drawCircles myimg
|
||||
myimg=: (5 34;orange) floodFill myimg
|
||||
myimg=: (5 36;red) floodFill myimg
|
||||
viewRGB myimg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue