logo

JeeperesesCreepers

//Code written by Luis Quinones @ [complicitMatter]
  //Feel free to use and modify the code in any way you want, please comment below with suggestions, ideas of any relevant throughts
  
  private void RunScript(bool reset, int ptCount, int dimension, bool connect, double conn_thresh, double moveValue, ref object A, ref object B, ref object C)
  {
    Random rnd = new Random();
    List<Vector3d> vecs = new List<Vector3d>();
    List<Point3d> returnedvecs = new List<Point3d>();

    if(reset){
      this.moveVecAmp = moveValue;
      this.moveList = new List<Vector3d>();
      this.dimensions = dimension;

      if(this.dimensions == 0){
        this.bb = new BoundingBox(-250, -250, 0, 250, 250, 0);
      }else{
        this.bb = new BoundingBox(-250, -250, -250, 250, 250, 250);
      }

      this.startList = new List<Vector3d>();

      for(int i = 0; i < ptCount; i++){
        if(this.dimensions == 0){
          this.moveVec = new Vector3d(rnd.Next(-1, 2), rnd.Next(-1, 2), 0);
          this.speedVec = new Vector3d(rnd.NextDouble(), rnd.NextDouble(), 0);
          this.startPos = new Vector3d(rnd.Next((int) bb.Min[0], (int) bb.Max[0]), rnd.Next((int) bb.Min[1], (int) bb.Max[1]), 0);

        }else{
          this.moveVec = new Vector3d(rnd.Next(-1, 2), rnd.Next(-1, 2), rnd.Next(-1, 2));
          this.speedVec = new Vector3d(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
          this.startPos = new Vector3d(rnd.Next((int) bb.Min[0], (int) bb.Max[0]), rnd.Next((int) bb.Min[1], (int) bb.Max[1]), (int) bb.Min[1]);

        }
        this.startList.Add(this.startPos);

        int switchDir = rnd.Next(-1, 1);
        if(switchDir < 0){
          this.speedVec *= this.moveVecAmp;
        }else{
          this.speedVec *= -this.moveVecAmp;
        }
        this.moveVec += this.speedVec;
        this.moveList.Add(this.moveVec);
      }
      creeperDudes = this.startList;

    }else{

      creepers creeperPts = new creepers(this.startList, this.moveList, bb, this.dimensions, connect, conn_thresh);
      creeperPts.move();

      this.startList = creeperPts.outputList;

      creeperDudes = this.startList;
      connectors = creeperPts.lineList;
      boundBox = this.bb;
    }
  }

  private List<Vector3d> moveList = new List<Vector3d>();
  private List<Vector3d> startList = new List<Vector3d>();

  private Vector3d startPos = new Vector3d();
  private Vector3d moveVec;
  private Vector3d speedVec;
  private BoundingBox bb;
  private int dimensions;
  private double moveVecAmp;

  public class creepers{

    private BoundingBox bbox;
    public Vector3d pos = new Vector3d();
    public List<Vector3d> posList = new List<Vector3d>();
    public List<Vector3d> posMoveList = new List<Vector3d>();
    public List<Vector3d> outputList = new List<Vector3d>();
    public List<Line> lineList = new List<Line>();
    private bool flag;
    private int dim;
    private bool conn;
    private double ct;

    public creepers(List<Vector3d> vecs, List<Vector3d> move, BoundingBox bb, int dimension, bool connect, double connThresh){

      this.posList = vecs;
      this.posMoveList = move;
      this.bbox = bb;
      this.dim = dimension;
      this.conn = connect;
      this.ct = connThresh;
    }

    public void move(){
      for(int i = 0; i < this.posList.Count; i++){
        this.pos = new Vector3d();
        this.pos += this.posList[i];
        this.checkLoc();

        if(this.flag){
          Vector3d temp = this.posMoveList[i];
          if(this.dim == 0){
            if(this.pos.X >= (int) this.bbox.Max[0] || this.pos.X <= (int) this.bbox.Min[0]){
              temp.X *= -1;
            }
            if(this.pos.Y >= (int) this.bbox.Max[1] || this.pos.Y <= (int) this.bbox.Min[1]){
              temp.Y *= -1;
            }
          }else{
            if(this.pos.X >= (int) this.bbox.Max[0] || this.pos.X <= (int) this.bbox.Min[0]){
              temp.X *= -1;
            }
            if(this.pos.Y >= (int) this.bbox.Max[1] || this.pos.Y <= (int) this.bbox.Min[1]){
              temp.Y *= -1;
            }
            if(this.pos.Z >= (int) this.bbox.Max[2] || this.pos.Z <= (int) this.bbox.Min[2]){
              temp.Z *= -1;
            }
          }
          this.posMoveList[i] = temp;
        }
        this.pos += this.posMoveList[i];
        this.outputList.Add(this.pos);
        if(this.conn){
          link();
        }
      }
    }

    public void link(){
      for(int i = 0; i < this.outputList.Count; i++){
        Point3d othercreeper = (Point3d) this.outputList[i];
        double dist = othercreeper.DistanceTo((Point3d) this.pos);

        if(dist > 0 && dist < this.ct){
          Line l = new Line(othercreeper, (Point3d) this.pos);
          lineList.Add(l);
        }
      }
    }
    
    public void checkLoc(){
      flag = new bool();
      if(!this.bbox.Contains((Point3d) this.pos)){
        this.flag = true;
      }else{
        this.flag = false;
      }
    }
  }
Update
  • Share