홍수 채우기 알고리즘을 사용하는 몇 가지 방법이 있습니다. 매우 간단합니다홍수 채우기 알고리즘 분석
맨 위에있는 첫 번째 장애물로 이동하십시오. 바닥
에
변화 픽셀 컬러 검사를 변경해두면하면서/우측 픽셀들은 다른 색에
예인 경우 : 색이 항목도 (stack.push())
루프.
Stack<Point> st = new Stack<Point>(); 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++; } }
점은 난 그냥
//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;
이러한없이
else if (spRight && p.X < b.Width - 1 && b.GetPixel(p.X + 1, p.Y) != oldColor) {
spRight = false;
}
는, 코드가 잘 작동이 부분을 이해하지 않는다는 것입니다, 그리고 그것은을 가지고있는 것처럼 보인다 같은 양의 반복. 이 라인이 정말로 쓸모가 없거나 그냥 이해하지 못한다면 제가 도와 줄 수 있습니까? (내 친구가 목적없이 그들을 넣어 믿을 수 없어)
왜 그들을 추가 왜 친구를 물어 보지? – Kevin
atm과 접촉하지 않습니다. 휴일 :/ – user1321706