Seems like there must be a better way?
https://paintz.app seems to be able to do this without precomputing all of the spaces you could flood.
https://paintz.app seems to be able to do this without precomputing all of the spaces you could flood.
The method in TFA is however faster for static images, after the preprocessing.
https://en.wikipedia.org/wiki/Flood_fill
I was hoping the author had figured out some clever solution involving some implementation detail of HTML Canvas.
This method might not produce perfect results when the paint can 'escape' through a tiny gap that isn't visible on the downscaled version... But at the same time, I suspect most users don't actually want the paint to escape through a tiny gap, so that might be the right behaviour.
http://www.adammil.net/blog/v126_A_More_Efficient_Flood_Fill...