Have you ever done that thing where you stand in front of a mirror & hold up a mirror…so you’re looking at a reflection of yourself in a reflection of yourself in a reflection of yourself…or when you take a photo of someone taking a photo of you taking a photo of them taking a photo of you…? Recursive functions mess with my head in a very similar way. But let’s take a tumble down the rabbit hole.

A recursive function is, predictably, a function that recurs…that is to say that it calls itself from within itself. For example, imagine a function drawLine() {}…(guess what it does). Well what if, having drawn my line, I then, at the bottom of the function, call drawLine()..? So drawing a line causes the drawing of a line, which causes the drawing of line…and what does this mean..?

We have a really long line

But, crucially, these sort of patterns can yield some spectacularly complex & beautiful looking results (they can also yield some spectacularly infinite loops that will crash your browser, so it’s worth putting some sort of incrementing counter in the function & capping how many times it can be called). Future articles will give more detail, perhaps even unpacking some of the code that has produced the following images, but for now, enjoy the elegant beauty of these fairly simple examples of recursion & start exploring the world of generative art…