Random Walks

In 2014 I read a lot of The Nature of Code by Daniel Shiffman and got inspired to make a bunch of things in Processing. This is the first thing that I made. You can see some of the other things I made here.

The Nature of Code is a book about mathematical principles in the physical world and how to program natural systems using Processing. The very first example is to make a random walker class whose instantiation looks something like this:

The above random walker is represented by a single black pixel who randomly moves up, down, left or right with equal probability. I iterated on this example a few times: I first made the random walker into a 10x10 pixel square that changed color over time. In this version it's easier to see the walker's current movement and overall walk.

I next made it so that the walker could only walk on squares it hadn't already visited. This way, the canvas will fill up entirely with colored squares and then stop.

Looking at these beautifully moving walkers made me want to paint a river with them, so I did that.

Here I used multiple random walkers and made each a little less random by setting their probability of moving right to 0.5, moving up to 0.25, and moving down to 0.25.