class Node { // properties - extend and hack! float x,y,z,mass; String name; Node[] connections; float strength; String type; boolean alive; float diameter; float springLen; ParticleSystem physics; Particle p; Spring[] springs; Attraction[] attractions; ArrayList circuits; PVector pv; color clr; int sw; Node(String _name, float _mass, float _x, float _y, float _z, ParticleSystem _physics){ x = _x; y = _y; z = _z; pv = new PVector(x,y,z); mass = _mass; name = _name; connections = new Node[0]; alive = true; springLen = 5; clr= color(255,255,255); sw=1; if(name.contains("a")){ strength = 300; type = "a"; diameter = 30; } else if(this.name.contains("b")){ strength = 200; type = "b"; diameter = 20; } else if(this.name.contains("c")){ strength = 100; type = "c"; diameter = 10; } else if(this.name.contains("x")){ //do nothing } else if(this.name.contains("g")){ strength = 100; type = "g"; diameter = 10; } else{ int t = 0; //int t = floor(random(0,3)); if(t == 0){ type = "a"; strength = 3; diameter = 15; } else if(t == 1){ type = "b"; strength = 2; diameter = 20; } else{ type = "c"; strength = 1; diameter = 10; } } physics = _physics; connections = new Node[0]; springs = new Spring[0]; attractions = new Attraction[0]; p = physics.makeParticle(mass, x, y, z); } void avoid(Node[] nodes){ if(p.isFixed() == false && alive == true){ int index = -1; PVector thisP = this.pv; for(int i=0; i< nodes.length; i++){ PVector thatP = nodes[i].pv; float checkDistance = thisP.dist(thatP); float closestCircle = (nodes[i].diameter/2) + (this.diameter/2); if (checkDistance > 0 && checkDistance < closestCircle/4 && nodes[i].type != "g" && nodes[i].type != "x"){ closestCircle = checkDistance; index = i; } } if (index >= 0){ Node target = nodes[index]; PVector targetPos = new PVector(target.x, target.y, target.z); PVector direction = PVector.sub(targetPos, thisP); direction.limit(2); thisP.sub(direction); this.x = thisP.x; this.y = thisP.y; this.z = thisP.z; p.position().set(x,y,z); } } } void fix(){ p.makeFixed(); } Spring connect(Node a, boolean _on){ connections = (Node[]) append(connections, a); Spring theSpring = physics.makeSpring(this.p, a.p, springLen, 1, springLen ); springs = (Spring[]) append( springs, theSpring ); if(!_on){ theSpring.turnOff(); } return theSpring; } Node[] getConnections(){ return connections; } void plot3D(float sc){ if(alive == true){ strokeWeight(sw*2); stroke(clr); point(x,y,z); strokeWeight(1); for(int i=0; i 0 && d <= lastClosest && d < 100){ lastClosest = d; index = i; } } } if(index >= 0){ //println("CONVERGING!"); PVector f = all[index].pv; PVector aPos = PVector.add(b, f); aPos.div(2); for(int j= 0;j 0){ int i = (int)random(connections.length); theNode = connections[i]; } n++; } if(theNode != _parent && theNode.alive == true){ if(path.contains(theNode) == true ){ int s = path.indexOf(theNode); if(s != 0){ path.subList(0, s).clear(); } path.add(theNode); if(path.size()> 4){ circuits = path; } } else{ path.add(theNode); childCount += theNode.findCircuits( maxGenerations, currentGeneration + 1, lineWidth/2.0, this, path ); } } } return childCount; } void tieEnds(){ if(p.age() > 1 && connections.length < 2 && p.isFixed() == false){ int index = -1; float bestDist = 9999999; PVector thisP = this.pv; for(int i=0; i< form.length; i++){ PVector thatP = form[i]; float checkDistance = thisP.dist(thatP); if (checkDistance < bestDist){ bestDist = checkDistance; index = i; } } if (index >= 0){ PVector target = form[index]; this.x = target.x; this.y = target.y; this.z = target.z; p.position().set(x,y,z); fix(); } } } void torque(){ if(type != "x" || type != "g"){ for(int i=0; i < springs.length; i++){ Spring s = springs[i]; if(type.equals("a")){ s.setRestLength((1/(frameCount+1))*(p.age()*10)); } else if(type.equals("b")){ s.setRestLength((5/(frameCount+1))*(p.age()*10)); } else if(type.equals("c")){ s.setRestLength((2/(frameCount+1))*(p.age()*10)); } float st = s.strength(); s.setStrength(st + (s.restLength()*50)); } } } }