循环。
Stack st = new Stack();
bool spLeft, spRight;
Bitmap b = canvas.buffer;
st.Push(start);
spLeft = spRight = false;
Point p = new Point();
while (st.Count > 0)
{
//going as far top as possible (finding first obstacle)
p = st.Pop();
while (p.Y >= 0 && b.GetPixel(p.X, p.Y) == oldColor) p.Y--;
p.Y++;
spLeft = spRight = false;
//looping on every oldColored pixel in column
while (p.Y < b.Height && b.GetPixel(p.X, p.Y) == oldColor) {
b.SetPixel(p.X, p.Y, state.currentColor); //setting new color
//checking if left pixel is oldColored and if it doesn't belong to span
if (!spLeft && p.X > 0 && b.GetPixel(p.X - 1, p.Y) == oldColor) {
st.Push(new Point(p.X - 1, p.Y));
spLeft = true;
}
//checking if left pixel isn't oldColored and if it belongs to span
else if (spLeft && p.X > 0 && b.GetPixel(p.X - 1, p.Y) != oldColor) {
spLeft = false;
}
if (!spRight && p.X < b.Width - 1 && b.GetPixel(p.X + 1, p.Y) == oldColor) {
st.Push(new Point(p.X + 1, p.Y));
spRight = true;
}
else if (spRight && p.X < b.Width - 1 && b.GetPixel(p.X + 1, p.Y) != oldColor) {
spRight = false;
}
p.Y++;
}
}