/* ---------------------------------------------- Computing Kaizen Studio Advanced Studio VI Spring 2010 Columbia University GSAPP Cutting Bodies Code by Ayaz Momin http://www.arch.columbia.edu/ http://proxyarch.com/kaizen This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License -----------------------------------------------*/ import traer.physics.*; Graph myGraph; ParticleSystem physics; int cutTime = 0; Node[] corners; Node[] edges; Node[] internal; int counter = 0; float[][] pts; int dim = 22; //int dim = 20 float spacing = 20.0; int cuts1, cuts2, cuts3, cuts4; float repulsionForce = -200.0; float minDistance = 10.0; float springStrength = 1.0; float springLength = spacing *.6; float moveMod = spacing * .75; void setup (){ size(600, 450); cuts1 = cuts2 = cuts3 = cuts4 = 0; reset(); } void reset(){ physics = new ParticleSystem(0,0,0,1); myGraph = new Graph(physics); float margin = 80; for(int i=0;i0){ Node toRig = myGraph.getNodeByName((counter-1)+"" ); myGraph.connectNodes(theNode, toRig, springStrength, springLength); } if(i>0){ Node toRig = myGraph.getNodeByName((counter-dim)+"" ); myGraph.connectNodes(theNode, toRig, springStrength, springLength); } if(i==0 && j==0){ theNode.fix(); } if( j==dim-1 && i==dim-1){ theNode.fix(); } counter++; } } background(230); smooth(); } void draw (){ cutTime--; fill(230,40); noStroke(); rect(0,0,width,height); Node[] all = myGraph.getNodes (); Node[] corners = new Node [0]; Node[] edges = new Node [0]; Node[] internal = new Node [0]; myGraph.update(); fill(120); stroke(255); //myGraph.plot3D(1); // DETERMINE CONDITION OF EDGE for(int i=0; i 0){ boolean allowed = false; if(victim != null){ switch(victim.cutDepth) { case 0: allowed = true; cuts1++; break; case 1: allowed = true; cuts2++; break; case 2: allowed = true; cuts3++; break; default: allowed = true; cuts4++; break; } } if(allowed == true && cutTime < 1){ for(int i=0; i 0){ Node swap = a; a = b; b = swap; } myGraph.removeNode(victim); Node sideA = myGraph.addLeaf( counter+"", next, 1.0,.1,spacing); sideA.cutDepth = victimDepth + 1; sideA.p.position().set( location.x + random(-5,5), location.y + random(-5,5), location.z); myGraph.connectNodes(sideA, a, springStrength, springLength ); counter++; Node sideB = myGraph.addLeaf( counter+"", next, 1.0,.1,spacing); sideB.cutDepth = victimDepth + 1; sideB.p.position().set( location.x + random(-5,5), location.y + random(-5,5), location.z ); myGraph.connectNodes(sideB, b, springStrength, springLength ); counter++; if(cutCount > 0){ myGraph.connectNodes(sideA, backA, springStrength, springLength ); myGraph.connectNodes(sideB, backB, springStrength, springLength ); } if(cutCount == 0){ origA = sideA; origB = sideB; } cutCount++; victim = next; backB = sideB; backA = sideA; cutting = false; for(int i=0; i<3; i++){ Node theTest = victim.connections[i]; theTest.unfix(); if(theTest.connections.length == 4){ PVector testAlign = new PVector(theTest.x+random(-1,1), theTest.y+random(-1,1), theTest.z); testAlign.sub( location.x, location.y, location.z); if( degrees( PVector.angleBetween( testAlign, direction)) < 40){ cutting = true; next = theTest; cutToward = i; } } } if(cutCount > 8-sq(victimDepth+1)){ cutting = false; victim.fix(); } } } if(startCut == true){ float moveAmount = cutCount/2 * moveMod; origA.fix(); PVector unitZ = new PVector(0,0,1); PVector foldDirection =unitZ.cross( direction); float r = random(-1,1); foldDirection.mult(r/abs(r)); //foldDirection.add(direction ); foldDirection.normalize(); origA.p.position().add(foldDirection.x * moveAmount, foldDirection.y * moveAmount, moveAmount/2.0); } physics.tick(.2); fill(255,200); noStroke(); ellipse(blobCenter.x, blobCenter.y, 50,50); } void mousePressed(){ reset(); }