# random walk 3D [no boundary + clusters]

Random Walk 1.5
Inspired by “The Nature of Code” by Daniel Shiffman and it’s python translator Jake Hebbert.
Using C# in Grasshopper for Rhinoceros

//	Philipp Siedler
//	Daniel Shiffman "The Nature of Code"
//	Random Walk 1.5
private void RunScript(int seed, int time, ref object A, ref object B, ref object C, ref object D, ref object E, ref object F)
{
List <Point3d> pList = new List<Point3d>();
List <Point3d> pListEx = new List<Point3d>();

List <int> xList = new List<int>();
List <int> indexList = new List<int>();

Walker w = new Walker();
Random random = new Random(seed);

int counter = 0;

for(int i = 0; i < time; i++){
int rnd = random.Next(0, 6);
w.step(rnd);

if(w.boundRebounceCount < 100){
}
else{
}
counter++;

if(indexList.Count() == 1){
indexList[0] = counter;
}

if(w.x == 0 && w.y == 0 && w.z == 1){
counter = 0;
}
}

A = pList;
B = xList;
C = counter;
D = indexList;
E = pListEx;
F = w.growthCounter;

}

public class Walker
{
public double x;
public double y;
public double z;
public int rnd;
public int boundRebounceCount;
public int explosionNum;
public int growthCounter;

//Constructor that takes arguments.
public Walker(){
x = 1.0;
y = 1.0;
z = 1.0;
rnd = 0;
growthCounter = 0;
boundRebounceCount = 100;

}

public Point3d pos(){
Point3d posPt = new Point3d(x, y, z);
return posPt;
}

public int step(int rnd){

int choice = rnd;
int explosionNum = 0;

//GROWING UP
if(boundRebounceCount == 100 && growthCounter < 750){
if (choice <= 0){
x++;
growthCounter++;
}
else if(choice <= 1){
x--;
growthCounter++;
}
else if(choice <= 2){
y++;
growthCounter++;
}
else if(choice <= 3){
y--;
growthCounter++;
}
else if(z > 5 && choice <= 4){
z--;
growthCounter++;
}
else if(choice <= 5){
z++;
growthCounter++;
}
}

if (growthCounter == 750){
boundRebounceCount = explosionNum;
growthCounter = 0;
}
else if (z <= 0){
boundRebounceCount = explosionNum;
}

//EXPLODING
double factor = 1;

if(boundRebounceCount == 99){
x = 0;
y = 0;
z = 1;
boundRebounceCount = 100;
}

else if(boundRebounceCount < 99){
if(choice == 0){
x = x - factor;
boundRebounceCount++;
}
if(choice == 1){
x = x + factor;
boundRebounceCount++;
}
if(choice == 2){
y = y - factor;
boundRebounceCount++;
}
if(choice == 3){
y = y + factor;
boundRebounceCount++;
}
if(choice == 4){
z = z + factor;
boundRebounceCount++;
}
if(z >= 10 && choice == 5){
z = z - factor;
boundRebounceCount++;
}
else if(choice == 5){
z = z + factor;
boundRebounceCount++;
}
}

return choice;
}
}

Output:

This site uses Akismet to reduce spam. Learn how your comment data is processed.