A generic flood fill algorithm that works on arbitrary 2d data.
npm install ts-flood-fillts
floodFill(
// start coordindates
x, y,
// color or value to replace with
replacementColor,
// method that returns color at coordinates
(x, y) => foo.myGetColor(x, y),
// method that set color at coordinates.
// NOTE: the color passed in will be the same object
// instance as replacementColor, so clone it or read
// its parameters appropriately
(x, y, c) => foo.mySetColor(x, y, c),
// bounds check
(x, y) => foo.myIsInBounds(x, y),
// equality check, since can operate on basic types as well as objects
(a, b) => a == b
);
``