As the first assignment in my Nature of Code class, we were asked to create a sketch that shows the behavior of a “random walker.” In other words, we had to create something that moved in a random and surprising way.
One of the first sketches I wrote in Processing more than ten years ago, was a sketch that added random X values and random Y values to create random movement, but I was frustrated that the parameters somehow made the walker appear to move too randomly. This time, I wanted to make a sketch where the subject would move in a smoother way or at least a more consistent way. This time I have the movement based on vectors that allowed me to lock the velocity at a specific value with only the angle of movement changing. The angle range can also be locked providing each walker with a kind of personality. Some walkers move more erratically, while others follow a straight(ish) line.
Each walker is an instance of the class called “walker.” When an instance is created, it is given a random starting coordinate, a starting radius, a starting velocity, a starting color, and a starting angle range. The angle range is probably the most crucial for defining behavior. The walkers that have large angular ranges mean that they will follow more erratic paths as the change in their direction can be selected from a greater number of options. For example, if Walker “A” has an angle range of 180º, it can go forward, 90º left, 90º right, and everything between. This will result in a path that has sharp turns and lots of small loops. If Walker “B” has an angle range of 15º, it will be confined to a mere 7.5º to the left and 7.5º to the right. This will create a path with large arcs and minimal variation. Both of these behaviors can be seen in the actual sketch.
I added the feature of the wrap-around behavior to make sure I wouldn’t lose any of my walkers and then realized that these could make interesting tileable graphics, so I also have each walker copied four more times, above, below, left and right. The black rectangle shows where the tiles would connect.
Click to add more walkers.
See the code below: