I'm looking for a way to create a function that fills a grid of pixels w/ a given colour.
If the user clicks on one pixel, my idea is to check if each of the pixel's neighbours (up, down, left, and right) is the same colour as the pixel that was clicked. For each neighbour, if it's the same colour, change it to black. If the neighbour pixel isn't the same colour as the original pixel clicked, it would be a stop condition.
Each of my pixels lives inside an array, and structure of each pixel object is as follows:
{
colour: 0xFFFFFF, // Or some other color
neighbours: {
l: PixelObj,
r: PixelObj,
u: PixelObj,
d: PixelObj
}
}
If the pixel is on the edge of the grid (40x40), one of it's neighbour objects will be null
instead of a reference to another pixel.
Is there a way to create a function that fills a colour recursively, given each pixel in a grid that knows it's neighbours properties?