grass fire algorithm

can some one tell me how a grass fire algorithm works and how to use it for selecting neighboring pixels of a chosen pixel in an image ???

Essentially you start by selecting one pixel in the image. Then for each neighbouring pixel (up to eight) you test if that pixel is the same as the one selected. If so you also select that pixel and repeat the test on the new pixel’s neighbours. You repeat this for each new pixel selected until there are no more selectable pixels. You can use this for exact colour matches, or you can use a tolerance level that selects pixels that only differ slightly to the one selected.

thats what i exactly need for my project now… i gotto select a pixel and then set a tolerance level to select all the neghboring pixels of a similar(not same) color value.
can u give me a typical code for the algorithm,pls ???

I know the theory but never tried to code it. Hopefully someone else can help. If not try google again.