Description Whenever the circle hits the boundary of the window, the program plays a keyboard note and switch to a random background color for less than a second.
import processing.sound.*;
SoundFile a;
SoundFile b;
SoundFile hihat;
int u;
int v;
int speedU = 1;
int speedV = 6;
void setup(){
background(0);
size(800,800);
a = new SoundFile (this, "1.aif");
b = new SoundFile (this, "2.aif");
hihat = new SoundFile (this, "hihat.aif");
}
void drawFace (float u, float v, color c, float size){
fill(c);
ellipse(u,v,size,size);
}
void draw(){
background(0);
drawFace (u, v, color(#FFC9DE),100);
u=u+speedU;
v=v+speedV;
if (u>width||u<0){
speedU=-speedU;
a.play();
background(random(255),random(255),random(255));
delay(1);
}if(v>height||v<0){
speedV=-speedV;
b.play();
background(random(255),random(255),random(255));
}
}
void keyPressed(){
if(key=='h');
hihat.play();
}
Leave a Reply
You must be logged in to post a comment.