Skip to main content
  1. Blog/

Boxed In: a look at recursion

Author
Lance Barker
Exploring my own creative expression and building things that help people.
Table of Contents

#

“To understand recursion, you must understand recursion.”

(How I love this.)

I made one of my little generative art animations with the idea of seeing what kind of effect I could get from recursively drawing some simple shape or shapes over and over again with small changes.

I used just a box and a circle and came up with this:

While coding, this happens when a function being defined is applied within it’s own definition, like this:

function makeBox(x, y, s) {
    translate(x, y);
    rotate(s / 10 + (col / 2) % 360);
    // blah, blah, blah
    {
        makeBox(x + s / 4, y, s / 2);
        makeBox(x - s / 4, y, s / 2);
        makeBox(x, y + s / 4, s / 2);
    }
}

In this case the function makeBox calls itself within it’s own definition. This can be very powerful. And so much fun!

I hope you enjoy.

Related

Latest image

The latest image from my generative art series was a nice surprise. It started as this: for (i in 1:500) { x = x*((0.98)^i)*cos(i) y = y*((0.98)^i)*sin(i) } which is simple R code that generates 500 x, y points that spiral. That code gave me this:

The Beauty In Numbers, 2a: Circular Matrices

I consider myself a fledgling geometer. That is, someone who is inspired by the beauty in numbers and wants to make stuff in that realm. Geometric images and like that. Some call it Sacred Geometry. I prefer to call it Inspired Geometry. So, I’m an Inspired Geometer? Okay. I can go with that.