洪水填充算法
Flood fill is an algorithm mainly used to determine a bounded area connected to a given node in a multi-dimensional array. It is a close resemblance to the bucket tool in paint programs.
泛洪填充是一种算法,主要用于确定连接到多维数组中给定节点的有界区域。 它与绘画程序中的存储桶工具非常相似。
The most approached implementation of the algorithm is a stack-based recursive function, and that’s what we’re gonna talk about next.
该算法最常用的实现是基于堆栈的递归函数,这就是我们接下来要讨论的内容。
它是如何工作的? (How does it work?)
The problem is pretty simple and usually follows these steps:
该问题非常简单,通常按照以下步骤操作:
- Take the position of the starting point. 取得起点位置。
Decide wether you want to go in 4 directions (N, S, W, E) or 8 directions (N, S, W, E, NW, NE, SW, SE).
确定是否要沿4个方向( N,S,W,E )或8个方向( N,S,W,E,NW,NE,SW,SE )移动。
- Choose a replacement color and a target color. 选择替换颜色和目标颜色。 <