// i used this code as a backdrop to a performance of my song called 'the game' . all the words here are all the lyrics to my song // Thanks to Daniel Shiffman for his recursive tree which i used because it goes with my song and the logo of my label is also a tree so perfect really // www.58records.co.uk and www.rasha.co.uk import pitaru.sonia_v2_9.*; //PImage bg; PFont f; int a,b; // how many seconds between each saveFrame int timeDelay; int x= 0; int y = 0; //create the array String[] textArray = {"","","","","","","","","sit", "me","on", "a tree","a tree", "and", "wait", "for", "the breeze", "to", "clear", "me", "it's", "only", "a breath", "away", "a gasp away", "i", "will", "take", "my", "time", "in place and history", "and", "when","the", "fuse", "blows","and so shall i", "i go", "place a stone", "on", "the", "hanging clothes", "and", "watch","the ghost","try and understand", "why", "we","cross", "each", "day", "with our blindfolds on", "and", "look the other way","and", "watch","the sun","with our blindfolds on","we","watch","the sun","with our blindfolds on", "i", "will", "plea", "my", "crime", "against", "the case","i face", "and", "when", "the", "fuse", "blows", "and", "so", "shall","I","I.....Go", "I'll play amongst the boys", "waiting", "patiently", "for", "my turn", "to","come to me", "and", "when", "it", "does", "you shall see", "the","sparks", "flying", "off", "my tree","but", "until", "then", "I'll Play", "i'll","play", "the", "game", "to","stay", "sane", "I'll play the game", "to stay sane"}; float theta; void setup(){ size(1024,768); stroke(255); framerate(4); // b is how many items there are in my array b=textArray.length; // delay between each word that comes on the screen timeDelay = 8; // Load the font from the sketch's data directory f = loadFont("Meta.vlw.gz"); Sonia.start(this); LiveInput.start(); ellipseMode(CENTER); rectMode(CENTER); background(100,200,100); } void draw(){ smooth(); colorMode(RGB); stroke(255); // get level from microphone int m = int(LiveInput.getLevel()*1000); if (m<100){ background(100,200,100); } //changing the colours of the rectangles with the level of sound fill(500-m,1000-m,m,300-m); //creating the frame of rectangles for(int i=0; i<32; i++) for(int j=0; j<2; j++) if (m>0 &&m < 100){ rect(40+i*30,50+j*30, m/10+ random(10),m/10+random(10)); rect(40+i*30,700+j*30, m/10+random(10),m/10+random(10)); } else{ ellipse(40+i*30,50+j*30, m/6+random(10),m/6+random(10)); ellipse(40+i*30,700+j*30, m/6+random(10),m/6+random(10)); } for(int j=0; j<23; j++) for(int i=0; i<3; i++) if (m>0 &&m < 100){ rect(920+i*30,60+j*30, m/10+random(10),m/10+random(10)); rect(30+i*30,60+j*30, m/10+random(10),m/10+random(10)); } else{ ellipse(920+i*30,60+j*30, m/10+random(10),m/10+random(10)); ellipse(30+i*30,60+j*30, m/10+random(10),m/10+random(10)); } //making the text travel along the screen and then downwards while still going along if (x > width){ x = 0; y = y +50; } if (y>height-100){ y=0; } stroke(255); //changing the size of font with the level of sound textFont(f, 30f*m/12); fill (300,233,100,150); // making the text change colour of the level of sound got to a certain point if (m>350){ fill (0,0,0,250); } stroke(255); // making the words from with in my array come out one by one and then travel across the screen text(textArray[int(a)], x, y+70); x = x+50; // this is where the time delay for the words coming out is made if (millis()%timeDelay == 0){ fill (300,233,100,255); textFont(f, 40f*m/12); // i had the same words appear at another point of the screen text(textArray[int(a)], 350-(textArray.length*2), 400); a++; // when it reaches the end of my array to go back 10 places and then loop around the last 10 words forever if (a>b-1){ a=b-11; } } // this is for when it gets really loud, lots of tiny words start popping up randomly all over the screen if (m>300){ colorMode(HSB); fill (200,random(100,233),random(100),150); textFont(f, random(5,30)); text(textArray[int(a)], random(600) +200 , random(600)+200); text(textArray[int(a)], random(600) +200 , random(600)+100); text(textArray[int(a)], random(600) +200 , random(600)+300); text(textArray[int(a)], random(600) +200 , random(600)+200); text(textArray[int(a)], random(600) +200 , random(600)+100); text(textArray[int(a)], random(600) +200 , random(600)+300); text(textArray[int(a)], random(600) +200 , random(600)+200); text(textArray[int(a)], random(600) +200 , random(600)+100); text(textArray[int(a)], random(600) +200 , random(600)+300); text(textArray[int(a)], random(600) +200 , random(600)+200); text(textArray[int(a)], random(600) +200 , random(600)+100); text(textArray[int(a)], random(600) +200 , random(600)+300); } //code for the tree stroke(0,0,0,150); // Let's pick an angle 0 to 90 degrees based on the mouse position float a = (6*m / (float) width) * 90f; // Convert it to radians theta = radians(a); // Start the tree from the bottom of the screen translate(width/2,height); // Draw a line 60 pixels line(0,-300,0,-400); // Move to the end of that line translate(0,-400); // Start the recursive branching! branch(80); if(m>200){ //create 2nd tree line(-400,-100,-400,-200); // Move to the end of that line translate(-400,-200); // Start the recursive branching! branch(80); //create 3nd tree line(800,100,800,0); // Move to the end of that line translate(800,0); // Start the recursive branching! branch(80); //create 4th tree translate(-800,0); line(400,-100,400,-200); // Move to the end of that line translate(400,-200); // Start the recursive branching! branch(80); //create 5th tree translate(-400,200); line(100,500,100,400); // Move to the end of that line translate(100,400); // Start the recursive branching! branch(80); //create 6th tree translate(-100,-400); line(700,500,700,400); // Move to the end of that line translate(700,400); // Start the recursive branching! branch(80); } } 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!!!! // Here, ours is when the length of the branch is 2 pixels or less if (h > 2) { pushMatrix(); // Save the current state of transformation (i.e. where are we now) rotate(theta); // Rotate by theta line(0,0,0,0-h); // Draw the branch translate(0,-h); // Move to the end of the branch branch(h); // Ok, now call myself to draw two new branches!! popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state // 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(); } } public void stop(){ Sonia.stop(); super.stop(); }