You can use Flood fill to fill the region. It takes a start point (or start point ) as input and recursively fills an area, trying to fill its empty neighbors.
A simple stack based implementation in JavaScript:
isEmpty(point) is a function that checks if point (x, y) filled with a boundary color (in this case light green) or not.
setPixel(point) fills the point (x, y) with the foreground color (dark green, in your case).
the implementation of these functions is trivial, and I leave it to you.
In the above implementation, 4-connected is used . But it can easily be extended to 6 or 8-connected neighborhoods.
source share