int value8;
int value9;
int value10;
//int time;
int startTime;
int elapsedTime;
int elapsedTime2;
int startTime2;
int sizeX;
int sizeY;
int mins;
int rvalue;
int rvalue2;
int rvalue3;
int rvalue4;
int rvalue5;
int rvalue6;
int rvalue7;
int time;
float diam, x, y;
float r, g, b, a;
void setup() {
minim = new Minim(this);
player = minim.loadFile("Mix 1.mp3");
video = new Capture(this, width, height, 5);
prevFrame = createImage(video.width,video.height,RGB);
video.start();
smooth();
//size(400, 400, P3D);
size(1280, 800, P3D);
noStroke();
smooth();
colorMode(HSB, fftSize, 10, 10);
//frameRate(120);
ellipseMode(CENTER);
sizeX = 60;
sizeY = 30;
int l = 0;
player.play();
startTime = millis();
elapsedTime = millis() - startTime;
startTime2 = millis()/1000;
elapsedTime2 = millis()/1000 - startTime;
fft=new FFT(player.bufferSize(), player.sampleRate());
}
void draw() {
fft.forward(player.mix);
value = upDownCounter(255, 1);
value2 = upDownCounter(255, 5);
value3 = upDownCounter(255, 8);
value4 = upDownCounter(255, 13);
value5 = upDownCounter(225, 20);
value6 = upDownCounter(255, 10);
value7 = upDownCounter(255, 20);
value8 = upDownCounter(225, 2);
value9 = upDownCounter(225, 3);
value10 = upDownCounter(360, 5);
// if(time > 222000){
// fill(0,0,0,5);
// rect(0,0,width,height);
// }else { fill(0,0,0,0);
// rect(0,0,0,0);
//println (time);
//println (startTime);
video();
//if(time > 222000){
// fill(0,0,0,5);
//rect(0,0,width,height);
// }
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
//fill(value2*(band), value3*(band), value4*(band));
if (elapsedTime > (108000)){
fill(value2*band, value3*band, value4*band, 2);
rect(0, 0, width, height);
} else{
fill(value2*band, 0, 0, 5);
rect(0, 0, width, height);
}
}
pushMatrix();
if(time < 222000){
block();
block2();
block3();
block4();
popMatrix();
}
else if(time > 222000){
pushMatrix();
Rain();
Rain35();
Rain15();
rainMore();
popMatrix();
}
//saveFrame();
//background(value2*(band), value3*(band), value4*(band));
}
void video(){
if(time < 222000){
if (video.available()) {
// Save previous frame for motion detection!!
prevFrame.copy(video,0,0,video.width,video.height,0,0,video.width,video.height); // Before we read the new frame, we always save the previous frame for comparison!
prevFrame.updatePixels();
video.read();
}
}
loadPixels();
video.loadPixels();
prevFrame.loadPixels();
for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width; // Step 1, what is the 1D pixel location
color current = video.pixels[loc]; // Step 2, what is the current color
color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color
// Step 4, compare colors (previous vs. current)
float r1 = red(current); float g1 = green(current); float b1 = blue(current);
float r2 = red(previous); float g2 = green(previous); float b2 = blue(previous);
float diff = dist(r1,g1,b1,r2,g2,b2);
// Step 5, How different are the colors?
// If the color at that pixel has changed, then there is motion at that pixel.
if (diff > threshold) {
// If motion, display black
pixels[loc] = color(0);
} else {
// If not, display white
pixels[loc] = color(255);
}
}
}
updatePixels();
}
void block(){
smooth();
elapsedTime = millis() - startTime;
for (int j = 0; j < fftSize; j++) {
float band3 = fft.getBand(j);
pushMatrix();
if(elapsedTime > 197500){
fill(j, 300+100*(band3), 100, value8);
arc(random(width), random(height), 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 300+100*(band3), 100, value8);
arc(random(width), random(height), 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 187000){
fill(j, 300+100*(band3), 100, value8);
arc(random(width), random(height), 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
} else if(elapsedTime > 142000){
fill(j, 300+100*(band3), 100, value8);
arc(640, 400, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 119000){
fill(j, 300+100*(band3), 100, value8);
arc(640, 400, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 108000){
fill(j, 300+100*(band3), 100, value9);
arc(640, 400, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime < 108000){
fill(j, (300+100*(band3)), 100, value9);
arc(640, 400, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}
}
popMatrix();
}
void block2(){
for (int j = 0; j < fftSize; j++) {
float band3 = fft.getBand(j);
pushMatrix();
if(elapsedTime > 197500){
fill(j, 150+100*(band3), 100, value8);
arc(random(width), random(height), 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 150+100*(band3), 100, value8);
arc(random(width), random(height), 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 187000){
fill(j, 150+100*(band3), 100, value8);
arc(300, 400, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
} else if(elapsedTime > 142000){
fill(j, 150+100*(band3), 100, value8);
arc(300, 400, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 119000){
fill(j, 150+100*(band3), 100, value8);
arc(300, 400, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else {
fill(j, (150+100*(band3)), 100, 0);
arc(300, 400, 50+band3 * (j+1)/8, 50+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}
}
}
void block3(){
for (int j = 0; j < fftSize; j++) {
float band3 = fft.getBand(j);
pushMatrix();
if(elapsedTime > 197500){
fill(j, 150+100*(band3), 100, value8);
arc(random(width), random(height), 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 150+100*(band3), 100, value8);
arc(50, 400, 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 150+100*(band3), 100, value8);
arc(50, 400, 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 187000){
fill(j, 150+100*(band3), 100, value8);
arc(50, 400, 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
} else if(elapsedTime > 142000){
fill(j, 150+100*(band3), 100, value8);
arc(50, 400, 10+band3 * (j+1)/8, 10+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else {
fill(j, (150+100*(band3)), 100, value8);
arc(640, 400, 100+band3 * (j+1)/8, 100+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}
}
}
void block4(){
for (int j = 0; j < fftSize; j++) {
float band3 = fft.getBand(j);
pushMatrix();
if(elapsedTime > 197500){
fill(j, 150+100*(band3), 100, value8);
arc(random(width), random(height), value+band3 * (j+1)/8, value+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 150+100*(band3), 100, value8);
arc(950, 400, value+band3 * (j+1)/8, value+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 192500){
fill(j, 150+100*(band3), 100, value8);
arc(950, 400, value+band3 * (j+1)/8, value+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else if(elapsedTime > 187000){
fill(j, 150+100*(band3), 100, value8);
arc(950, 400, value+band3 * (j+1)/8, value+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
} else if(elapsedTime > 142000){
fill(j, 150+100*(band3), 100, value8);
arc(950, 400, value+band3 * (j+1)/8, value+band3 * (j+1)/8, aj*j, aj*(j+1));
popMatrix();
}else {
fill(j, (150+100*(band3)), 100, value8);
arc(640, 400, 100+band3 * (j+1)/4, 100+band3 * (j+1)/4, aj*j, aj*(j+1));
popMatrix();
}
}
}
void Rain(){
smooth();
noFill();
value = upDownCounter(255, 2);
value4 = upDownCounter(255, 5);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(value4,0,0,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
popMatrix();
if(time > 219000){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 205500){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 192000){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 138){
stroke(value4,value5,value6,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
// stroke(value, value5, value3, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
popMatrix();
}else if(time > 82){
stroke(value4,value5,value6,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
//popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
// popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else {if(time > 55){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
// popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else if(time > 27){
ellipse(825,250, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else {
ellipse(500, 250, i*(band/5),i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
// popMatrix();
}
}
}}
void Rain35(){
smooth();
noFill();
value3 = upDownCounter(255, 3);
value5 = upDownCounter(255, 8);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(255,value5,255,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
popMatrix();
if(time > 205500 + 222000){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 192000 + 222000){
stroke(225, 225, 225, 0);
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else { if(elapsedTime > 138 + 222000){
stroke(value3,value4,value5,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
// stroke(value6, 225, 225, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
popMatrix();
} else{ if(time > 82 + 222000){
stroke(value3,value4,value5,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
//popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
//popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 55 + 222000){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
//popMatrix();
stroke(0,235,235,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 27 + 222000){
ellipse(100,525, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else if(time > 222000){ ellipse(500, 250, i*(band/value3),i*(band/value3));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
// popMatrix();
}
}
}
}}
void Rain15(){
smooth();
noFill();
value2 = upDownCounter(255, 1);
value6 = upDownCounter(225, 13);
for (int i = 0; i < fftSize; i++) {
float band = fft.getBand(i);
stroke(255,255,value6,random(255));
strokeWeight(random(8));
pushMatrix();
rotate(radians(15));
popMatrix();
if(time > 192000 + 222000){
stroke(225, 225, 225, random(225));
ellipse(random(height), random(width), i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
popMatrix();
} else if(time > 138){
stroke(value,225,0,random(50));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
//stroke(value2, value3, value6, 20);
// rect(random(1000), random(1000), i*(band*value), i*(band*value));
popMatrix();
} else { if(time > 82 + 222000){
stroke(value2,value3,value6,random(100));
ellipse(357,278, i*(band*value), i*(band*value));
sizeX+=1;
sizeY+=1;
//popMatrix();
stroke(value4,0,0,random(255));
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
// popMatrix();
stroke(0,205,205,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else if(time > 55 + 222000){
ellipse(800,500, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
//popMatrix();
stroke(0,255,255,random(255));
ellipse(100,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
} else { if(time > 27 + 222000){
ellipse(700,100, i*(band/5), i*(band/5));
sizeX+=10;
sizeY+=5;
popMatrix();
}else if(time > 222000) { ellipse(500, 250, i*(band/value2),i*(band/value2));
sizeX+=10;
sizeY+=5;
popMatrix();
sizeX = 60;
sizeY = 30;
// popMatrix();
}
}
}
}
}
void rainMore() {
//generating random numbers for r,g,b,a
value7 = upDownCounter(255, 2);
for (int i=0; i<255; i++) {
r=random(200-i);
g=random(200-i);
b=random(200);
a=random(value7);
//generating randoms for diameter,x&y position
diam = random(20);
x = random(width);
y = random(height);
if(time > 138 + 222000){
stroke(value2, value3, value6, a);
rect(x, y, diam, diam);
} else if(time > 222000){
//drawing ellipses
noStroke();
fill(r,g,b,a);
ellipse(x,y,diam,diam);
}
}
}
int upDownCounter(int maxValue, int factor) {
int doubleMaxValue = 2*maxValue;
int fcd = (frameCount/factor)%doubleMaxValue;
return (fcd<maxValue)?fcd:doubleMaxValue-fcd; // this line is also important!
}
void stop()
{
player.close();
player1.close();
minim.stop();
super.stop();
}