/* ben yee final 12/9/07 an interactive art piece that allows the user to select colors for the shades of bubbles */ import processing.video.*; import krister.Ess.*; AudioChannel myChannel; FFT myFFT; PImage buttons; PFont f; color red = color(255,0,0,150); color green = color(0,255,0,150); color blue = color(0,0,255,150); color whichShade; int xpos, ypos; int xspeed = 2; int yspeed = 2; int xdirection = 1; int ydirection = 1; float speed; boolean musicOn; Capture myCapture; Spring2D s1, s2; float gravity = 6.0; float mass = 2.0; void setup() { size(1000, 240); background(200); frameRate(30); smooth(); myCapture = new Capture(this, 120, 90, 30); //initiate the video, resolution and frame rate xpos = width; ypos = height/2; buttons = loadImage("buttons.png"); musicOn = false; f = loadFont("LucidaSans-13.vlw"); //load font textFont(f); displayInstructions(); Ess.start(this); // Start Ess myChannel = new AudioChannel("flows.mp3"); // load music myFFT = new FFT(512); s1 = new Spring2D(0.0, width/2, mass, gravity); s2 = new Spring2D(0.0, width/2, mass, gravity); } void draw() { noStroke(); int level=(int)(myFFT.getLevel(myChannel)*height); // get audio level s1.update(xpos, level); s1.display(xpos, level); s2.update(s1.x, s1.y); s2.display(s1.x, s1.y); fill(whichShade); ellipse(xpos,level,2,2); // dot in motion fill(255); // the white outline box rect(0,0,120,240); image(buttons,0,0); // the tools image(myCapture, 0, 30); // the video window fill(200); // clear screen rect(0,120,120,20); fill(red); // the initial available colors - R, G, B, Black, White rect(0,140,120,20); fill(green); rect(0,160,120,20); fill(blue); rect(0,180,120,20); fill(0); rect(0,200,120,20); fill(whichShade, 80); // give ellipse tool the color with translucent effect if(musicOn==true){ // update the position of the shape xpos = xpos + ( xspeed * xdirection ); ypos = ypos + ( yspeed * ydirection ); myChannel.play(Ess.FOREVER); } if (xpos > width-speed || xpos < 120) { // keep the line in motion in the workspace xdirection *= -1; } if (ypos > height-speed || ypos < 0) { ydirection *= -1; } if(mouseX > 120){ // call the circle draw function if mouse in workspace variableEllipse(mouseX, mouseY, pmouseX, pmouseY); } } void captureEvent(Capture myCapture) { //read video myCapture.read(); } void mouseReleased(){ if(mouseX > 0 && mouseX < 30 && mouseY > 0 && mouseY <30){ //play and pause button triggers musicOn=true; } else if (mouseX > 30 && mouseX < 60 && mouseY > 0 && mouseY <30){ musicOn=false; myChannel.pause(); } if(mouseX > 60 && mouseX < 90 && mouseY > 0 && mouseY <30){ //display instructions clearCanvas(); displayInstructions(); } if(mouseX > 90 && mouseX < 120 && mouseY > 0 && mouseY <30){ save("art.tif"); } if(mouseY > 120 && mouseY < 140){ //clear the screen clearCanvas(); } if(mouseX < 120 && mouseY > 40){ //selection fill color int tempShade = get(mouseX, mouseY); float r = red(tempShade); float g = green(tempShade); float b = blue(tempShade); whichShade = color(r, g, b); } } void variableEllipse(int x, int y, int px, int py) { speed = abs(x-px) + abs(y-py); // calculates speed of mouse stroke(speed); ellipse(x, y, speed, speed); // slow mouse draws small ellipse. quick mouse draws large ellipse. } void displayInstructions(){ fill(0); // fill black text("play/pause music and movement. display instructions. 'print' work" , 130, 20); text("see the user and use any color from this palette",130, 80); text("clear canvas", 130, 135); text("use red", 130, 155); text("use green", 130, 175); text("use blue", 130, 195); text("use black", 130, 215); text("use white", 130, 235); fill(whichShade); // return to user selected fill } void clearCanvas(){ fill(200); rect(120,0,width-120,height); } void stop() { Ess.stop(); // When program stops, stop Ess too super.stop(); }