/* :: a city is not a tree, according to Christopher Alexander, meaning that its structure is more complex than the diagrammatic branching distribution of a tree : : however a city is a tree in its morphology, following the fractal distribution of its networked space :: :: this application is a first expression of a system which follows the fractal design of a tree, importing one element in order to augment the complexity of the tree structure this element is the live input of sound : i used as a starting point two examples in Processing : Liveinput and Tree : artemis papageorgiou */ // counter on, redraws every 10 seconds the background // without the semi-transparent rectangle. // and with large liveSpectrum trunk import pitaru.sonia_v2_9.*; float theta; void setup(){ size(720,450); Sonia.start(this); // Start Sonia engine. LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands. frameRate(30); smooth(); fill(255,5); } int counter; void draw(){ if(counter++%600 == 0) background(250); rect(0,0,width,height); //background(255); stroke(255); // getMeterLevel(); // Show meter-level reading for Left/Right channels. getSpectrum(); // Show FFT reading float a = (LiveInput.spectrum[1] / (float) width) * 90f; // Let's pick an angle 0 to 90 degrees based on the mouse position theta = radians(a); // Convert it to radians } void getSpectrum(){ strokeWeight(0); // stroke(0,230,0); LiveInput.getSpectrum(); float trunk; for ( int i = 0; i < LiveInput.spectrum.length; i+=2){ // line(i*6, height, i*6, height - LiveInput.spectrum[i]/10); pushMatrix(); translate(i*6, height); //GLEN'S INPUT trunk = LiveInput.spectrum[i]/10; //GLEN //if i divide this value by 10 i go back to the normal trunk line(0,0,0,-trunk); // trunk stroke(0,LiveInput.spectrum[i]/5,0); translate(0,-trunk); // move first branch branch(LiveInput.spectrum[i]/10); //GLEN'S INPUT popMatrix(); } } void getMeterLevel(){ //shows volume // get Peak level for each channel (0 -> Left , 1 -> Right) // Value Range: float from 0.0 to 1.0 // Note: use inputMeter.getLevel() to combine both channels (L+R) into one value. float meterDataLeft = LiveInput.getLevel(); float meterDataRight = LiveInput.getLevel(); fill(0,100,0); float left = meterDataLeft*height; float right = meterDataRight*height; rect(width/2 - 100, height, 100 , left*-1); rect(width/2 , height, 100, right*-1); } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); } void branch(float h) { // Each branch will be 2/3rds the size of the previous one h *= 0.66f; // All recursive functions must have an exit condition!!!! if (h > 2) { pushMatrix(); rotate(theta); line(0,0,0,-h); translate(0,-h); branch(h); //recursion popMatrix(); // Repeat the same thing, only branch off to the "left" this time! pushMatrix(); rotate(-theta); line(0,0,0,-h); translate(0,-h); branch(h); popMatrix(); } }