Gallery details
Code Creates Random Creeper Agents moving around in 2d & 3d. Their proximity is indexes by links between creepers. We will continue building off of this class – C#
—Quick Study building off of Creepers example. Here we have creepers moving randomly in 2d & 3d. When they each the boundary they turn around and go the opposite direction. I wanted to diagram their proximity as a visual cue for the later studies. The link connects any creepers that are within a threshold of each other. We will use this value to trigger interaction between them. Performance of the component is very quick, we are using the timer to run the component live without a number of iterations.—Using Grasshopper C# components for the code snippets below – All Test code is provided on an ‘as-is’ basis for evaluation, testing and commenting purposes. I am not responsible for any damage incurred by its usage. Use at your own risk.
Base Creeper Agent Class - C# Code
//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
Recently in Portfolio
- Nike A.I.R Prototypes
- HE.6 2020 Prototype
- [A]nisochromatic Meshing
- PYTORCH-CLASSIFIER
- CULEBRA.NET
- Nike Zoom Superfly Elite
- Nike Footscape Flyknit DM
- Jordan Hyperdunk React
- KA-HELMET
- PARAPRAXIS
- [001.HRR] CONCEPT BIKE
- [C]ucarachas
- [S]eeker
- BENGBU CITY OPERA
- [O]h Baby
- [E]l Papa
- [S]hatter.Brain
- [S]tigmergy
- [F]orces
- CULEBRA.JAVA
- [C]ulebra.MultiBehaviors
- 2040:LUNAR.OUTPOST[a]
- [S]ticky Stuff
- [S]entinels
- [G]allopingTopiary
- [P]erlin
- [E]ternal Wanderers
- [W]heelie
- [M]esh Crawlers
- [E]l Nino
- [L]a Silla
- [3]D BabyMaking Trackstars
- [3]D Trackers
- [2]D BabyMaking Trackers
- [T]rackers
- CULEBRA GRASSHOPPER
- culebra.[M]eshCrawlers.3D
- culebra.[H]ybrid.3D
- culebra.[F]lorgy
- culebra.[F]ockers.3D
- culebra.[F]ockers.2D
- culebra.[N]oisey.3D
- culebra.[S]elfOrg
- [D]rippin
- [S]labacube
- culebra.[N]oisey.2D
- [C]reepyCrawlers
- [J]eepresesCreepers
- [C]reepers
- [T]2000
- RELUXOED
- [SRC] . Semi Rigid Car
- PUFFER PLEATNESS
- EMERGEN[CY]
- [L]iquified
- [S]uckedComp
- [X]plosion
- MR. EW
- [H]airGoo
- [B]alled
- [n]injaStars
- [b]loomer
- [t]rip city
- TAPE GUNNED
- [B]oom
- [M]iller Time
- [D]elamjam
- [B]rain Zapper
- [B]ig Bird
- IIIIIIII 00137
- [E]gg Tube Pavillion
- [A]llice’s Easter Tree
- [S]weet Honey
- [U]M.Urgent
- [t]oo.urgent
- [B]onnie..+..Clyde
- [B]io Mess
- [EL]Mojado.Virus
- [W]HAT the …!
- [H]ot Lava
- [P]leat Diddy
- [t]erminator easter egg
- Mr. BB
- [B]less You
- [J]acky Jack
- [F]antastic + Interactive
- [S]oo_Minimally_Pathed
- [P]uffer Fish.Fab
- [M]an Eater
- [F]ace Sukka
- [W]eave Machine
- Sportbike Racing
- Grappling
- Kart Racing
Leave a reply