/* ---------------------------------------------- Computing Kaizen Studio Advanced Studio VI Spring 2010 Columbia University GSAPP Tracking Bodies Code by Anna Karigianni http://www.arch.columbia.edu/ http://proxyarch.com/kaizen This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License -----------------------------------------------*/ class Node { // PROPERTIES float x,y,z,mass; String name; Node[] connections; color clr; int reach; PVector pos; float thickness ; float diagonal ; // PARTICLE SYSTEM ParticleSystem physics; Particle p; Spring[] springs; Attraction[] attractions; float traffic; float threshold; boolean carFriendly; PVector b; int id; //CONSTRUCTOR Node(String _name, float _mass, float _x, float _y, float _z, ParticleSystem _physics, Node[] _others ){ reach = 0; id = 0; traffic = 1; carFriendly = true; x = _x; y = _y; z = _z; pos = new PVector(x, y, z); mass = _mass; name = _name; connections = new Node[0]; physics = _physics; connections = new Node[0]; springs = new Spring[0]; attractions = new Attraction[0]; p = physics.makeParticle(mass, x, y, z); //makeParticle(float mass, float x, float y, float z) for(int i=0; i<_others.length; i++){ if( p != _others[i].p){ Attraction a = physics.makeAttraction( p,_others[i].p, -1000, 10); Attraction b = physics.makeAttraction( _others[i].p, p, -1000, 10 ); attractions = (Attraction[]) append(attractions, a); _others[i].attractions = (Attraction[]) append(_others[i].attractions, b); } } } //METHOD 1 int recursiveReach( int maxGenerations, int currentGeneration, float lineWidth, Node _parent){ int childCount = 1; if(_parent != null){ strokeWeight(lineWidth); line(x, y, _parent.x, _parent.y); } if( currentGeneration < maxGenerations){ for(int i=0; i.1) box(diagonal); popMatrix(); if (diagonal > .1 ){ for(int i=0; i id){ PVector start = new PVector (x,y,z); PVector a = new PVector ((connections [i].x) - x+.001, (connections [i].y) - y+.001, (connections [i].z)- z+.001); a.normalize(); a.mult(diagonal/2.0); start.add(a.x, a.y, a.z); a.normalize(); a.mult( spacing - diagonal/2.0 - min(connections[i].traffic, spacing)/2.0 ); noStroke(); fill((min(255, traffic*tMod)+min(255, connections[i].traffic*tMod))/2.0,255,255); if(a.mag() > .01 ){ aligned_box (a, start, diagonal*.707, min(connections[i].traffic, spacing)*.707); } } } } } //METHOD 7 void aligned_box(PVector a, PVector start, float thicknessA, float thicknessB){ int startShape = 0; float buffer = 0; float amt = .01; PVector unit_x = new PVector(1,0,0); PVector unit_y = new PVector(0,1,0); PVector unit_z = new PVector(0,0,1); a.add( amt, amt, amt); PVector flat = new PVector(a.x, a.y, 0.0); float rot_z = PVector.angleBetween(flat, unit_x); PVector cross = unit_x.cross(flat); if(cross.z > 0){ rot_z = radians(360) - rot_z; } float rot_y = PVector.angleBetween(flat, a); if(a.z > 0){ rot_y = radians(360) - rot_y; } PVector b = new PVector(rot_y, rot_z); pushMatrix(); translate(start.x, start.y, start.z); rotateZ( -rot_z ); rotateY( rot_y ); translate( a.mag()/2.0 ,0,0); // shrink a's magnitude to reflect a buffer float newMag = max(0.0 , a.mag() - buffer*2); a.normalize(); a.mult(newMag); noStroke(); float offset = .75 * (2*PI); if(a.z > .5){ offset = .125 * (2*PI); } for(int i=startShape; i<4; i++){ beginShape(QUADS); vertex( a.mag()/2.0, sin(PI*-.25 + offset + i*HALF_PI)*thicknessB , cos(PI*-.25 + offset+ i*HALF_PI)*thicknessB) ; vertex( -a.mag()/2.0, sin(PI*-.25 + offset+ i*HALF_PI)*thicknessA , cos(PI*-.25 + offset+ i*HALF_PI)*thicknessA); vertex( -a.mag()/2.0, sin(PI*.25 + offset+ i*HALF_PI)*thicknessA , cos(PI*.25 + offset+ i*HALF_PI)*thicknessA); vertex( a.mag()/2.0, sin(PI*.25 + offset+ i*HALF_PI)*thicknessB , cos(PI*.25 + offset+ i*HALF_PI)*thicknessB); endShape(CLOSE); } popMatrix(); } //METHOD 8 void old_aligned_box(PVector a, PVector start, float thickness){ PVector unit_x = new PVector(1,0,0); PVector unit_y = new PVector(0,1,0); PVector unit_z = new PVector(0,0,1); PVector flat = new PVector(a.x, a.y, 0.0); float rot_z = PVector.angleBetween(flat, unit_x); PVector cross = unit_x.cross(flat); if(cross.z > 0){ rot_z = radians(360) - rot_z; } float rot_y = PVector.angleBetween(flat, a); if(a.z > 0){ rot_y = radians(360) - rot_y; } PVector b = new PVector(rot_y, rot_z); pushMatrix(); translate(start.x, start.y, start.z); rotateZ( -rot_z ); rotateY( rot_y ); translate( a.mag()/2,0,0); box(a.mag(),thickness,thickness ); popMatrix(); } //METHOD 9 void plot2D(float sc){ stroke(0); for(int i=0; i