For another submission to Viz as Art contest at Tableau, I wanted to create something involving randomness and random walk specifically. But I found that the classic random walk algorithm creates results that are, well…too random, as opposed to the organic, botanical shapes I was looking for. Luckily, someone has already thought of developing a “Random Walk with Transition Probabilities that Depend on Direction of Motion”. It sounds nerdy, but that is just the recipe that Mother Nature uses to build branches on a blueberry bush, dandelion’s see head or the maple tree outside my window. In particular, a particle always moves forward and changes direction or stays the course dependent on a given probability. One of the chapters in Clifford Pickover’s book “Computers, Pattern, Chaos and Beauty” describes this in more detail.
As with Lorenz Attractor visualization, I wrote a program in Processing to generate the points and export them to a text file. Below is a complete listing of the code:
[code language=”java”]
PrintWriter textFile;
//number of branches
int branchNum = 200;
//scale factor for angle theta
float delTheta = .9;
//scale factor for radius
float delRadius = 0.05;
//probability of transmission
float pt = 0.2;
//number of steps
int stepNum = 150;
//direction angle
float Theta = 0;
void setup(){
size(1000,1000);
background(0);
//initialize output text file
//textFile = createWriter(“txtfiles/points.txt”);
for (int branch = 0; branch < branchNum; branch++) {
//set initial conditions for each branch
float x0 = width/2;
float y0 = height/2;
float radius = 1;
float res = 0;
float dir = 1;
float lastDir = 1;
float thresh = 0;
strokeWeight(0);
stroke(0);
fill(random(1,255), random(1,255), random(1,255));
//stroke(random(1,255), random(1,255), random(1,255));
for (int step = 0; step < stepNum; step++) {
if (step == 0) {
res = random(0,1);
if (res > 0.5) {
dir=1;
} else {
dir=-1;
}
res = res * dir;
Theta = Theta + (res * delTheta);
radius = radius + delRadius;
float x = radius * cos(Theta) + x0;
float y = radius * sin(Theta) + y0;
line(x0, y0, x, y);
x0 = x;
y0 = y;
lastDir = dir;
} else {
if(lastDir == -1) {
thresh = pt;
} else {
thresh = 1 – pt;
}
res = random(0,1);
if (res > thresh) {
dir = 1;
} else {
dir = -1;
}
res = res * dir;
Theta = Theta + (res * delTheta);
radius = radius + delRadius;
float x = radius * cos(Theta) + x0;
float y = radius * sin(Theta) + y0;
line(x0, y0, x, y);
ellipse(x,y,10,10);
x0 = x;
y0 = y;
lastDir = dir;
//save output to text file
//textFile.println(branch + “,” + x + “,” + y);
//textFile.flush();
//exit();
}
}
}
}
[/code]
Just by changing one or two parameters, one can create an infinite number of patterns, some more organic looking than others. Here are sample outputs from Processing:
I imported the points into Tableau and played with different shapes, sizes an colours to achieve the best look. In the end, I settled for a basic grey circle with white outline. At first the monochrome chart was an uninteresting jumble of random points but after I added Branch field (unique branch number) to the Level of Detail, all tendrils got nicely separated revealing their organic structure.
You should take part in a contest for one of the finest sites on the net. I am going to highly recommend this blog!
Can I simply say what a comfort to uncover someone that genuinely understands what they are discussing on the web. You certainly realize how to bring a problem to light and make it important. More and more people really need to look at this and understand this side of your story. It’s surprising you aren’t more popular given that you most certainly possess the gift.