You are effectively doing a flood fill and there are many good algorithms out there that can do this efficiently. You might want to look at them.
You are effectively doing a flood fill and there are many good algorithms out there that can do this efficiently. You might want to look at them.