Thursday, January 21, 2021

Genuary 2021 Day 21: "Function"

 


This one was a relatively simple implementation of the prompt, once I decided what the prompt meant to me. The literal prompt on the Genuary page says:

function f(x) { 
    DRAW(x); 
    f(1 * x / 4); 
    f(2 * x / 4); 
    f(3 * x / 4); 
}

Which is easy enough to read, if you're into code, but I wasn't just going to paste that into my code, it required a certain amount of interpretation - what is x? And if x is not a numeric thing, what does it mean to divide or multiply x by numbers?

So, I stepped back a bit and turned the pseudocode above into more human-friendly instructions:
  1. At each step, you will start with a region of the page.
  2. Draw something that fills that region
  3. Then split the region into four sub-regions
  4. For the first three of the four sub-regions, recurse to step 1
Which I think pretty well captures the feeling of the pseudocode, but affords a little more freedom, especially in how the region is split.

My drawing step is just to draw a (colored) rectangle that fills the region. When drawing using my AxiDraw, I just have a single black pen hooked up.

I inset the rectangle to keep edges from overlaying each other.

To split the rectangle, I randomly pick a half split, quarter split, and three-quarters split location along the long axis of the rectangle. I randomly choose whether to output children 1, 2, and 3 or 2, 3, and 4, which might be a stretch from the original code, but I consider it an orientation detail; 2, 3 and 4 is really just 1, 2, and 3 from the other side of the rectangle, so it's fine.





I think this looks a little like a couple server racks, mostly filled.

Or maybe a Rockwell Automation Retro Encabulator:



Tools Used: AxiDraw, Pentel 5mm pen
Languages Used: Python
Development Time: ~30 minutes
Drawing Time: ~5 minutes
What's Generative Here: Each box is subdivided randomly, and colored randomly.



No comments:

Post a Comment