The aim of this challenge is to demonstrate the use of a recursive algorithm used in most Graphic Editing Software when you use the fill tool to quickly and automatically fill a selected area with a solid colour.
To demonstrate this algorithm we will first initialise a 2D-array called grid that will represent our picture, each cell being a pixel of colour. We will use three integer values to represent the colours white (=0), black (=1) and purple (=2).
We will prefill our grid with mainly white pixels as well as a few random black blocks randomly positioned on the grid. We will then use a recursive algorithm, starting from a random position on the grid, to colour all adjacent white pixels using a recursive approach:
Python Code
Here is the Python code to create a visual demonstration of our recursive flood-fill algorithm: