The Sierpinski gasket
Discover how recursive algorithms can generate the Sierpinski gasket, a fractal pattern made by repeatedly dividing and drawing squares. Learn to implement multiple recursive calls and understand the stopping condition to create this visual representation of recursion.
We'll cover the following...
So far, the examples of recursion that we've seen require you to make one recursive call each time. But sometimes you need to make multiple recursive calls. Here's a good example, a mathematical construct that is a fractal known as a Sierpinski gasket:
As you can see, it's a collection of little squares drawn in a particular pattern within a square region. Here's how to draw it. Start with the full square region, and divide it into four sections like so:
Take the three squares with an