[SOLVED] How should I replicating the fill or bucket tool in a 2d array?

Edit: Found a solution online while researching Flood Filling thanks to actual. It’s a simple recursive method that works very well. Here’s a link to the javascript example (also doable in Java): http://www.somethinghitme.com/2012/03/07/html5-canvas-flood-fill/

I’m currently working on a level editor for an Android game. My goal is to add cool tools such as:

  • pencil: Add single textures to the grid
  • eraser: remove texture from grid
  • bucket: fill in neighbor textures

I can’t seem to find any tutorials on how to fill in an arbitrary geometric area for the bucket tool. I’m not necessarily looking for source code, I just can’t seem to figure out how to go about filling in parts of a 2d array. I’ve considered using path-finding techniques, but I feel there may be a simple solution. Here is an image of what I’m dealing with:

I’ve created many level editors in the past, but never played around with the bucket tool idea. If you have any thoughts, please post about it; I’m sure other people would like to know how to do this as well. Thanks in advance!

PS - This tool is being written from HTML 5’s Canvas (Javascript), not Java. I’ve worked with both, so syntax isn’t really a problem; I’ll take any pseudo code.

The term you are looking for is Flood Fill or Boundary Fill.

That’s exactly what I was looking for! Thank you for the quick response.