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;
    indexList.Add(counter);

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

      if(w.boundRebounceCount < 100){
        pListEx.Add(w.pos());
      }
      else{
        pList.Add(w.pos());
      }
      counter++;


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

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



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

  }

  // <Custom additional code> 
  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:

random walk 3D [boundary + clusters] 2.0

Random Walk 1.4.1
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.4.1
 private void RunScript(int seed, int time, ref object A, ref object B, ref object C, ref object D, ref object E)
  {
    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;
    indexList.Add(counter);

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

      if(w.boundRebounceCount < 100){
        pListEx.Add(w.pos());
      }
      else{
        pList.Add(w.pos());
      }
      counter++;


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

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



    A = pList;
    B = xList;
    C = counter;
    D = indexList;
    E = pListEx;

  }

  // <Custom additional code> 
  public class Walker
  {
    public double x;
    public double y;
    public double z;
    public int bound;
    public int upperBound;
    public int rnd;
    public int boundRebounceCount;
    public int explosionNum;

    //Constructor that takes arguments.
    public Walker(){
      x = 1.0;
      y = 1.0;
      z = 1.0;
      bound = 10;
      upperBound = 100;
      rnd = 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){
        if (choice <= 0){
          x++;
        }
        else if(choice <= 1){
          x--;
        }
        else if(choice <= 2){
          y++;
        }
        else if(choice <= 3){ y--; } else if(z > 5 && choice <= 4){
          z--;
        }

        else if(choice <= 5){ z = z + 3; } if (x >= bound || x <= -bound){ boundRebounceCount = explosionNum; } if (y >= bound || y <= -bound){
          boundRebounceCount = explosionNum;
        }
        if (z <= 0 || z >= upperBound){
          boundRebounceCount = explosionNum;
        }
      }

      //EXPLODING
      double factor = 1;



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

      else if(boundRebounceCount < 99){ if(x >= -bound && choice == 0){
          x = x - factor;
          boundRebounceCount++;
        }
        else if(choice == 0){
          x = x + factor;
          boundRebounceCount++;
        }

        if(x <= bound && choice == 1){ x = x + factor; boundRebounceCount++; } else if(choice == 1){ x = x - factor; boundRebounceCount++; } if(y >= -bound && choice == 2){
          y = y - factor;
          boundRebounceCount++;
        }
        else if(choice == 2){
          y = y + factor;
          boundRebounceCount++;
        }

        if(y <= bound && choice == 3){
          y = y + factor;
          boundRebounceCount++;
        }
        else if(choice == 3){
          y = y - factor;
          boundRebounceCount++;
        }

        if(z <= upperBound && choice == 4){ z = z + factor; boundRebounceCount++; } else 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:

random walk 3D [boundary + clusters]

Random Walk 1.4
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.4
private void RunScript(int seed, int time, ref object A, ref object B, ref object C, ref object D, ref object E)
  {
    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;
    indexList.Add(counter);

    for(int i = 0; i < time; i++){       int rnd = random.Next(0, 7);       w.step(rnd);       if(w.boundRebounceCount > 0){
        pListEx.Add(w.pos());
      }
      else{
        pList.Add(w.pos());
      }
      counter++;

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

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

    A = pList;
    B = xList;
    C = counter;
    D = indexList;
    E = pListEx;

  }

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

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

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

    public int step(int rnd){

      int choice = rnd;
      int explosionNum = 100;

      //GROWING UP

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

        else if(choice <= 5){           z = z + 3;         }         if (x >= bound || x <= -bound){           boundRebounceCount = explosionNum;         }         if (y >= bound || y <= -bound){
          boundRebounceCount = explosionNum;
        }
        if (z <= 0 || z >= upperBound){
          boundRebounceCount = explosionNum;
        }
      }

      //EXPLODING
      double factor = 1;

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

      return choice;
    }
  }

Output:

random walk 3D [boundary + color]


Random Walk 1.3
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.3

private void RunScript(int seed, int time, ref object A, ref object B)
  {
    List <Point3d> pList = new List<Point3d>();
    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, 15);
      w.step(rnd);
      pList.Add(w.pos());
      counter++;

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

    A = pList;
    B = indexList;
  }
public class Walker
  {
    public int x;
    public int y;
    public int z;
    public int bound;
    public int upperBound;
    public int rnd;

    public Walker(){
      x = 0;
      y = 0;
      z = 0;
      bound = 15;
      upperBound = 150;
      rnd = 0;
    }

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

    public int step(int rnd){
      int choice = rnd;

      if (choice <= 1){
        x++;
      }
      else if(choice <= 3){
        x--;
      }
      else if(choice <= 5){
        y++;
      }
      else if(choice <= 7){
        y--;
      }
      else if(choice <= 9){
        z--;
      }
      else if(choice <= 14){
        z++;
      }

      if (x == bound || x == -bound){
        x = 0;
        y = 0;
        z = 0;
      }
      if (y == bound || y == -bound){
        x = 0;
        y = 0;
        z = 0;
      }
      if (z < 0 || z == upperBound){
        x = 0;
        y = 0;
        z = 0;
      }

      return choice;
    }
  }

Output:

random walk 3D [4 choices]

Random Walk 1.2
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.2

 private void RunScript(int seed, int time, ref object A)
  {
    List <Point3d> pList = new List<Point3d>();

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

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

    A = pList;
  }

public class Walker
  {
    public int x;
    public int y;
    public int z;
    public int rnd;

    public Walker(){
      x = 0;
      y = 0;
      z = 0;
      rnd = 0;
    }

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

    public int step(int rnd){
      int choice = rnd;
      if (choice == 0){
        x++;
      }
      else if( choice == 1){
        x--;
      }
      else if(choice == 2){
        y++;
      }
      else if(choice == 3){
        y--;
      }
      else if(choice == 4){
        z++;
      }
      else if(choice == 5){
        z--;
      }

      return choice;
    }
  }

Output:

random walk 2D [8 choices]

Random Walk 1.1
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.1

private void RunScript(int seed, int time, ref object A)
  {
    List  pList = new List();

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

    for(int i = 0; i < time; i++){
      int rnd = random.Next(0, 8);
      w.step(rnd);
      pList.Add(w.pos());
    }

    A = pList;
  }

public class Walker
  {
    public int x;
    public int y;
    public int rnd;

    public Walker(){
      x = 0;
      y = 0;
      rnd = 0;
    }

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

    public int step(int rnd){
      int choice = rnd;
      if (choice == 0){
        x++;
      }
      else if( choice == 1){
        x--;
      }
      else if(choice == 2){
        y++;
      }
      else if(choice == 3){
        y--;
      }
      else if(choice == 4){
        x++;
        y++;
      }
      else if(choice == 5){
        x--;
        y++;
      }
      else if(choice == 6){
        x--;
        y--;
      }
      else if(choice == 7){
        x++;
        y--;
      }
      return choice;
    }
  }

Output:

random walk 2D [4 choices]

Random Walk 1.0
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.0

private void RunScript(int seed, int time, ref object A)
{
    List <Point3d> pList = new List<Point3d>();

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

    for(int i = 0; i < time; i++){
        int rnd = random.Next(0, 4);
        w.step(rnd);
        pList.Add(w.pos());
    }

    A = pList;
}

public class Walker
{
    public int x;
    public int y;
    public int rnd;

    public Walker(){
        x = 0;
        y = 0;
        rnd = 0;
    }

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

    public int step(int rnd){
        int choice = rnd;
        if (choice == 0){
            x++;
        }
        else if( choice == 1){
            x--;
        }
        else if(choice == 2){
            y++;
        }
        else if(choice == 3){
            y--;
        }

        return choice;
    }
}

Output: