Prototyping interactive experiencesf

Page 15

Music without mouse pressed This code inserts music into the program. The window is still divided in 4 parts but the music starts without the mouse click , you just have to move the mouse cursor around the part that you want to activate.

Code: import ddf.minim.*; Minim minim; AudioPlayer player1; AudioPlayer player2; AudioPlayer player3; AudioPlayer player4;

void setup(){ size(400,400); minim = new Minim(this); player1 = minim.loadFile("1.mp3"); player2 = minim.loadFile("2.mp3"); player3 = minim.loadFile("3.mp3"); player4 = minim.loadFile("4.mp3"); } void draw(){ background(0); stroke(255); line(width/2,0,width/2,height); line(0,height/2,width,height/2); if(mouseX<width/2 && mouseY<height/2){ fill(255); rect(0,0,width/2,height/2); stroke(49); player2.pause(); player3.pause(); player4.pause(); player1.play(); }

else if(mouseX>width/2 && mouseY<height/2){ fill(255); rect(width/2,0,width/2,height/2); player3.pause(); player4.pause(); player1.pause(); player2.play(); } else if(mouseX>width/2 && mouseY>height/2){ fill(255); rect(width/2,height/2,width/2,height/2); player2.pause(); player4.pause(); player1.pause(); player3.play(); } else if(mouseX<width/2 && mouseY>height/2){ fill(255); rect(0,height/2,width/2,height/2); player2.pause(); player3.pause(); player1.pause(); player4.play(); } else{ background(192); line(width/2,0,width/2,height); line(0,height/2,width,height/2);} }

http://anamiran.tumblr.com/


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.