My code here:
import processing.sound.*;
AudioIn mic;
SoundFile s;
Amplitude am;
float[] pX = new float[50];
float[] pY = new float[50];
float[] speedU = new float[50];
float[] speedV = new float[50];
float sizeall=50;
color purple=color(5,39,175);
void setup(){
size(500,500);
background(255);
s = new SoundFile(this,"snare.wav");
mic = new AudioIn(this,0);
am = new Amplitude(this);
mic.start();
am.input(mic);
for (int i=1;i<=5;i++){
//print(1); those are for testing
pX[i]=(i*100.0-50.0);
//print(2);
pY[i]=i*100-50;
drawFace(pX[i],pY[i],purple,sizeall);
float a=random(5,10),b=random(5,10);
//print(3);
speedU[i]=a;
speedV[i]=b;
print(a);
println(b);
}
}
void draw(){
//println(am.analyze());
pushMatrix();
background(rbackground());
rotate(rtate());
for (int i=1;i<=5;i++){
move(pX[i],pY[i],sizeall,i);
}
popMatrix();
}
void move(float u,float v,float size,int i){
drawFace(u,v,rcolor(),size);
pX[i] += speedU[i];
pY[i] += speedV[i];
if (pX[i] > width || pX[i] < 0){
speedU[i] = -speedU[i];
s.play();
}
if (pY[i] > height || pY[i] < 0){
speedV[i] = -speedV[i];
s.play();
}
}
void drawFace(float x, float y, color c, float size){
size = map(am.analyze(),0,0.5,sizeall,width/2);
noStroke();
fill(c);
ellipse(x,y,size,size);
fill(255);
ellipse(x - size*0.1, y - size*0.1, size*0.1, size*0.1);
ellipse(x + size*0.1, y - size*0.1, size*0.1, size*0.1);
arc(x, y, size*0.6, size*0.6, 0, PI);
}
color rcolor(){
float a=random(0,255);
float b=random(0,255);
float c=random(0,255);
return color(a,b,c);
}
color rbackground(){
float rrr = map(am.analyze(),0,0.5,255,0);
return color(rrr);
}
float rtate(){
float b = map(am.analyze(),0,1,0,PI/4);
float a=random(-1,1);
if (a<=0){
b = -b;
}
return b;
}
Leave a Reply
You must be logged in to post a comment.