I'm working on creating algorithmic game levels like the "island" below: everything is generated computationally using random walks and other parameters for different "growing" terrains (blue is water, tan is beach, etc) including the shape of the island.
However, I'd like to be able to remove the isolated pieces that cannot be reached by the player (who can't enter the water). Here's a detail of the upper-right corner of the image - the bits I'd like to remove are in the upper-righthand corner:
I can remove single pixels of beach that are surrounded by blue on all sides very easily, but I can't figure out an efficient (and not super confusing) way to get the connected pieces of beach that never touch another color.
My gut says the solution is probably something recursive? Any suggestions? Thanks!
However, I'd like to be able to remove the isolated pieces that cannot be reached by the player (who can't enter the water). Here's a detail of the upper-right corner of the image - the bits I'd like to remove are in the upper-righthand corner:
I can remove single pixels of beach that are surrounded by blue on all sides very easily, but I can't figure out an efficient (and not super confusing) way to get the connected pieces of beach that never touch another color.
My gut says the solution is probably something recursive? Any suggestions? Thanks!
1