Random Walk – Example 10.1
This is an example of a structure that grows through a simple process known as a “Random Walk.” These random walks have several applications in scientific modeling, for example ecosystems, and even financial markets. A random walk also approximates (but not exactly) a scientific phenomenon known as Brownian Motion, which uses much more complex mathematics, but with sometimes similar results.
Here we are going to use a random walk to draw a series of 2 different kinds of circles, yellow and blue, which can be the same or different sizes. The rhythm between yellow circles and blue circles can also be changed to create different results.
The basic process is incredibly simple. We start with a point, which then gets put into a loop into Data Stream 0. In each of the iterations, the point first moves in one of 3 “x” directions (-1, 0, +1) and afterwards in one of 3 “y” directions (-1, 0, +1)
So the point which in this case is starting in position 5, could end up after each round in any of the nine positions show above. It will stay stationary if both the x and y movement values are equal to 0.
This new point is then contributed to an ongoing tally of points, which is kept in Data Stream 1. The point in its new location is then looped back in Data Stream 0 to undergo the process again and again. In the end there will be a cloud of points. Some spaces may have 2 or more points since the random walk will go back over itself.
The two images above show a polyline connecting the cloud of points in the order that they were drawn, as well as an interpolated NURBS to show how the walk moves back on itself. In both cases 500 points are drawn.
In the script image shown above, an important consideration is how the random numbers are generated and structured within the loop. Also, the Random seed cannot be the same for X and Y movement otherwise you will have movement in a straight line, since movement of -1 “x” will always be coupled with -1 “y” since the random number lists will be identical. In this case, the random number list is generated independent of the loop, with random values equal to the total number of repetitions we anticipate. Then, in each round, I use the “List Item” component to call one of the random values equal to the current round, so item 0 in round 0, item 1 in round 1, etc…
After the process finishes looping, the data is output from the loop. In these examples, the points are output and circles are drawn at each center. To make the pattern a bit more interesting, I dispatched the points into two lists based on a simple True/False test. This is similar to “Cull Nth”, but since I want to keep the items, and not cull them, i made a series of “0” values (which can be used in lieu of “False” in a T/F test and inserted a “1” at the end of the series to make a “True” value. This may not make much sense at first, and maybe there is a better way, but it didn’t occur to me at the time. So the circles that are “False” go on to become yellow circles while the “True” circles become blue. Since most positions are occupied by multiple points, sometimes a blue and yellow circle will be drawn at the same location. I can move the blue circles slightly up in the “Z” direction to have them display before the yellow, or vice versa.
In the first three iterations, I changed only the random number seed.
In the second three iterations, I kept the seed the same but changed the rhythm of Blue circles.
In the third set of 3 iterations, I changed the size of the various circles, as well as which set of circles displays on top.
And finally, I though I would add this image of a quick test I did where instead of blue circles, the script outputs trees in a certain rhythm. The tree size is based on how old they are. While it is a silly design, it actually follows to some degree ecological principles where a plant has random seed dispersal. OK, i just made that up 🙂