the canvas to work with, arranged as top to bottom, left to right elements
the width of the canvas
the height of the canvas
the type to replace. You may pass the existing value if you want to do what Paint does
the replacement value
the x-coordinate to start the fill (think of where the user clicked in Paint)
the y-coordinate to start the fill
A custom additional check to perform on each square before continuing. Returning true means keep flooding, returning false means stop. If null, it is not used.
Implements a flood fill algorithm, like the bucket tool in MS Paint.
Note it assumes what.length == width*height.