diff --git a/mods/fill_script.js b/mods/fill_script.js new file mode 100644 index 00000000..20247eaf --- /dev/null +++ b/mods/fill_script.js @@ -0,0 +1,42 @@ +function FillTool(x,y) +{ + if (!isEmpty(x,y)) + { + oldElement = pixelMap[x][y].element; + } + else + { + oldElement = undefined; + } + + Fill(x, y, oldElement); +} + +function Fill(x, y, oldElement) +{ + if (x < 0 || x >= width || y < 0 || y >= height) return; + + if (pixelMap[x][y] !== undefined && oldElement !== undefined) + { + if (pixelMap[x][y].element != oldElement) return; + } + else + { + if (pixelMap[x][y] != oldElement) return; + } + + + var index = currentPixels.indexOf(pixelMap[x][y]); + if (index > -1) + { + currentPixels.splice(index, 1); + } + currentPixels.push(new Pixel(x, y, currentElement)); + + Fill(x + 1, y, oldElement); + Fill(x - 1, y, oldElement); + Fill(x, y + 1, oldElement); + Fill(x, y - 1, oldElement); +} + +// Example: Fill(10, 10, pixelMap[10][10].element); \ No newline at end of file