/* ---------------------------------------------- Computing Kaizen Studio Advanced Studio VI Spring 2010 Columbia University GSAPP Grow/Die Bodies Code by Maider Llaguno 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 Band{ float level; Node NodeA; Node NodeB; int age; float angA,angB; float radA,radB; float numPoints; color Color; Band (Node _nodeA,Node _nodeB){ NodeA=_nodeA; NodeB=_nodeB; level = 0; age = 0; numPoints=2; Color=color(random(-20,20)+50,100,80); } void plot(int position){ age++; if( NodeA.pos.dist( NodeB.pos) > NodeB.rad+NodeA.rad+2 || NodeA.pos.dist( NodeB.pos)+ NodeB.rad + NodeA.rad <0.3*radMax || level/bandheigth > maxHeight){ // para cambiar tamano de pastilla modificar el valor que multiplica a radMax Bands.remove(position); } else{ level = 0.0; for(int i=0; i < position; i++) { Band element = (Band) Bands.get(i); if ( this.NodeA == element.NodeA || this.NodeB == element.NodeA || this.NodeA == element.NodeB || this.NodeB == element.NodeB) { // if so, then my level is above their level level = element.level + bandheigth; this.Color=element.Color; } } PVector perp1 = PVector.sub(NodeA.pos, NodeB.pos); float distance= NodeA.pos.dist(NodeB.pos); float angle = (atan2(perp1.y,perp1.x)); if (angle<0) angle = TWO_PI+angle; angle =angle +PI/2; PVector perp2 = PVector.sub(NodeA.pos, NodeB.pos); perp2.normalize(); angle = (atan2(perp2.y,perp2.x)); if (angle<0) angle = TWO_PI+angle; angle =angle -PI/2; angA = angle; radA = NodeA.rad; PVector perp3 = PVector.sub(NodeA.pos, NodeB.pos); perp3.normalize(); angle = (atan2(perp3.y,perp3.x)); if (angle<0) angle = TWO_PI+angle; angle =angle + PI/2; PVector perp4 = PVector.sub(NodeA.pos, NodeB.pos); perp4.normalize(); angle = (atan2(perp4.y,perp4.x)); if (angle<0) angle = TWO_PI+angle; angle =angle - PI/2; float detail = 20.0; float inc = PI/detail; angB = angle; radB = NodeB.rad; noStroke(); float linewidthOutside = 4; float linewidth = (radA+radB)/4; strokeWeight(1); pushMatrix(); translate(0,0,level); //extborder up noFill(); stroke(0,0,40,80); beginShape(); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y, 0.0); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y, 0.0); } endShape(CLOSE); stroke(0,0,40,80); beginShape(); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA-linewidth) + NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y, -bandheigth); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB-linewidth) + NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y,-bandheigth); } endShape(CLOSE); noStroke(); //extborder low noFill(); stroke(0,0,40,80); beginShape(); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y, -bandheigth); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y, -bandheigth); } endShape(CLOSE); //intborder up stroke(0,0,40,80); beginShape(); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA-linewidth) + NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y, 0.0); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB-linewidth) + NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y, 0.0); } endShape(CLOSE); noStroke(); if( this.NodeA.newnode == true || this.NodeB.newnode == true){ noStroke(); fill(0,0,100); age ++; if (this.age > 100){ this.age = 0; } } else { fill(Color); } //ext vertical thickness beginShape(TRIANGLE_STRIP); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y, 0.0); vertex( cos(angA + i*inc) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y, -bandheigth); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y, 0.0); vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y, -bandheigth); } vertex( cos(angA ) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA)*(radA+linewidthOutside) + NodeA.pos.y, 0.0); vertex( cos(angA ) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA)*(radA+linewidthOutside) + NodeA.pos.y, -bandheigth); endShape(CLOSE); //int vertical thickness beginShape(TRIANGLE_STRIP); // drawing first side for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA-linewidth) + NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y, 0.0); vertex( cos(angA + i*inc) *(radA-linewidth) + NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y, -bandheigth); } for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB-linewidth) + NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y, 0.0); vertex( cos(angB - i*inc) *(radB-linewidth) + NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y, -bandheigth); } vertex( cos(angA ) *(radA-linewidth) + NodeA.pos.x, sin(angA)*(radA-linewidth) + NodeA.pos.y, 0.0); vertex( cos(angA ) *(radA-linewidth) + NodeA.pos.x, sin(angA)*(radA-linewidth) + NodeA.pos.y, -bandheigth); endShape(CLOSE); //bandwidth beginShape(TRIANGLE_STRIP); for(int i=0; i<=detail; i++){ vertex( cos(angA + i*inc) *(radA-linewidth) + NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y, 0); vertex(cos(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y, 0); } endShape(CLOSE); beginShape(TRIANGLE_STRIP); for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB-linewidth)+ NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y, 0); vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y,0); } endShape(CLOSE); beginShape(QUAD_STRIP); vertex( cos(angA ) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA)*(radA+linewidthOutside) + NodeA.pos.y, 0); vertex( cos(angB ) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB)*(radB+linewidthOutside) + NodeB.pos.y, 0); vertex( cos(angA ) *(radA-linewidth) + NodeA.pos.x, sin(angA)*(radA-linewidth) + NodeA.pos.y, 0); vertex( cos(angB ) *(radB-linewidth) + NodeB.pos.x, sin(angB)*(radB-linewidth) + NodeB.pos.y, 0); endShape(CLOSE); beginShape(QUAD_STRIP); vertex( cos(angA+PI) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA+PI)*(radA+linewidthOutside) + NodeA.pos.y, 0); vertex( cos(angB+PI ) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB+PI)*(radB+linewidthOutside) + NodeB.pos.y, 0); vertex( cos(angA+PI) *(radA-linewidth) + NodeA.pos.x, sin(angA+PI)*(radA-linewidth) + NodeA.pos.y, 0); vertex( cos(angB+PI ) *(radB-linewidth) + NodeB.pos.x, sin(angB+PI)*(radB-linewidth) + NodeB.pos.y, 0); endShape(CLOSE); //bandwith beginShape(TRIANGLE_STRIP); for(int i=0; i<=detail; i++){ vertex(cos(angA + i*inc)*(radA-linewidth)+ NodeA.pos.x, sin(angA + i*inc)*(radA-linewidth) + NodeA.pos.y,-bandheigth); vertex( cos(angA + i*inc) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA + i*inc)*(radA+linewidthOutside) + NodeA.pos.y,-bandheigth); } endShape(CLOSE); beginShape(TRIANGLE_STRIP); for(int i=int(detail); i>=0; i--){ vertex( cos(angB - i*inc) *(radB-linewidth) + NodeB.pos.x, sin(angB - i*inc)*(radB-linewidth) + NodeB.pos.y, -bandheigth); vertex( cos(angB - i*inc) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB - i*inc)*(radB+linewidthOutside) + NodeB.pos.y, -bandheigth); } endShape(CLOSE); beginShape(QUAD_STRIP); vertex( cos(angA ) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA)*(radA+linewidthOutside) + NodeA.pos.y,-bandheigth); vertex( cos(angB ) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB)*(radB+linewidthOutside) + NodeB.pos.y, -bandheigth); vertex( cos(angA ) *(radA-linewidth) + NodeA.pos.x, sin(angA)*(radA-linewidth) + NodeA.pos.y,-bandheigth); vertex( cos(angB ) *(radB-linewidth) + NodeB.pos.x, sin(angB)*(radB-linewidth) + NodeB.pos.y, -bandheigth); endShape(CLOSE); beginShape(QUAD_STRIP); vertex( cos(angA+PI) *(radA+linewidthOutside) + NodeA.pos.x, sin(angA+PI)*(radA+linewidthOutside) + NodeA.pos.y, -bandheigth); vertex( cos(angB+PI ) *(radB+linewidthOutside) + NodeB.pos.x, sin(angB+PI)*(radB+linewidthOutside) + NodeB.pos.y, -bandheigth); vertex( cos(angA+PI) *(radA-linewidth) + NodeA.pos.x, sin(angA+PI)*(radA-linewidth) + NodeA.pos.y, -bandheigth); vertex( cos(angB+PI ) *(radB-linewidth) + NodeB.pos.x, sin(angB+PI)*(radB-linewidth) + NodeB.pos.y, -bandheigth); endShape(CLOSE); popMatrix(); } } }