Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions algorithm/category.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"etc": {
"name": "Uncategorized",
"list": {
"flood_fill": "Flood Fill"
}
}
}
9 changes: 9 additions & 0 deletions algorithm/etc/flood_fill/desc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Flood Fill": "Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array",
"References": [
"<a href='https://en.wikipedia.org/wiki/Flood_fill'>Wikipedia</a>"
],
"files": {
"flood_fill": ""
}
}
20 changes: 20 additions & 0 deletions algorithm/etc/flood_fill/flood_fill/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function FloodFill(i, j, oldColor, newColor) {

if (i < 0 || i >= G.length || j < 0 || j >= G[i].length) return;
if (G[i][j] != oldColor) return;

// set the color of node to newColor
G[i][j] = newColor;

tracer._select(i, j)._wait();
tracer._notify(i, j, G[i][j])._wait();

// next step four-way
FloodFill(i + 1, j, oldColor, newColor);
FloodFill(i - 1, j, oldColor, newColor);
FloodFill(i, j + 1, oldColor, newColor);
FloodFill(i, j - 1, oldColor, newColor);
}

FloodFill(4, 4, '-', 'a');

13 changes: 13 additions & 0 deletions algorithm/etc/flood_fill/flood_fill/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var tracer = new Array2DTracer ();
var G = [
['#', '#', '#', '#', '#', '#', '#', '#', '#'],
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
['#', '-', '-', '#', '-', '-', '-', '-', '#'],
['#', '#', '#', '-', '-', '-', '#', '#', '#'],
['#', '-', '-', '-', '-', '#', '-', '-', '#'],
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
['#', '#', '#', '#', '#', '#', '#', '#', '#']
];
tracer._setData(G);