Click here for a link to the above sketch.
I wrote this post before looking at the Diffusion-Limited Aggregation exercise, and now I realize that everything I was playing with to constrain the walker could be solved by literally doing what I just said: “constrain.” So, I’m leaving my original post below, because some of the artifacts were cool and weird, but in the end, simply calling “constrain” was a very straight-forward way to keep the walker inside the box. The above sketch does exactly that. And here were all my previous attempts and experiments with vectors and walkers.
First experiments
This is my first assignment from my first class with the one-and-only Dan Shiffman (applause). In our first session, Mr. Shiffman explained that vectors will more or less be the foundation of everything we do in the Nature of Code. I should also mention what the Nature of Code fundamentally is, which is basically recreating physical behaviors from the natural world through coding.
Our first assignment was to create a random walker. I made a few, but my first walker (shown above) I whipped up from scratch mostly to re-familiarize myself with .p5js after our long break (Here is a link to the code).This one does not use vectors, but it’s a random walker nonetheless. In this sketch, I spent a lot of time trying to figure out how to constrain the walker within the canvas bounds, but I’m realizing that it’s actually kind of complicated to do.
First, I tried reversing the values when the walker reached an edge, so “posx” would become “-posx",” and the same goes with Y. This definitely increases the likelihood that the walker will come back, but not by much. In the end, I found that you have to fundamentally change the probability of the walker once it reaches and edge in order to favor the likelihood that it will move away from the edge, which is actually pretty annoying to write out case by case. I also mapped the walker to a rainbow using HSB values, because why not a rainbow?
This sketch (click here for link) uses vectors to create the “levy flight,” which sort of mimics the way animals forage by manipulating the probability of randomness. I tried implementing my quick-and-dirty method of confining the walker and it had some pretty strange and awesome consequences.
If you give it enough time, the walker will draw lines across the entire canvas. Click here to see the sketch. It’s actually pretty cool. I’m trying to wrap my brain around exactly what’s happening in the math of these lines. In this sketch, I created the condition of making “posx” into “-posx” if the walker goes to the canvas edge, but I swapped it for “pos.x” and “pos.y" because I’m using vectors. At a glance I would say it has something to do with the relationship between “pos.x” and “prev.pos.”
And then I made when where I inverted “pos.x” and “pos.y” in the first coordinates of the line being drawn. Also weird and cool. Link here. See below: