How can I combine these two codes and make switch each other after 10 seconds?
in
Programming Questions
•
4 months ago
the first code:
- import krister.Ess.*;
- int bufferSize;
int steps;
float limitDiff;
int numAverages=1;
float myDamp=.1f;
float maxLimit,minLimit; - FFT myFFT;
AudioInput myInput;
int audioSensibility;
import processing.video.*; - // Size of each cell in the grid
int cellSize = 6;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
PShape star;
void setup() {-
smooth(); -
Ess.start(this);
bufferSize=512;
myInput=new AudioInput(bufferSize); - // set up our FFT
myFFT=new FFT(bufferSize*2);
myFFT.equalizer(true); - // set up our FFT normalization/dampening
minLimit=.049;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp);
myFFT.averages(numAverages); - // get the number of bins per average
steps=bufferSize/numAverages; - // get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit;
myInput.start();
audioSensibility = 500;
size(1920,900, P3D);
// Set up columns and rows
cols = width/2 / cellSize;
rows = height/2 / cellSize;
colorMode(RGB, 255, 255, 255, 70);
ellipseMode(CENTER); - // Uses the default video input, see the reference if this causes an error
video = new Capture(this, 640, 480);
video.start();
// frameRate(45); - filter(BLUR,15);
}
void draw() {
float percent=max(0,(myFFT.max-minLimit)/limitDiff);
// rect(600,11,50,(int)(198*percent));- if (video.available()) {
video.read();
video.loadPixels();
background(0,0,0);
//filter(BLUR,10);
// Begin loop for columns
for (int i = 0; i < cols;i++) {
// Begin loop for rows
for (int j = 0; j < rows;j++) { - // Where are we, pixel-wise?
int x = i*cellSize + cellSize/2;
int y = j*cellSize + cellSize/2;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
// Each rect is colored white with a size determined by brightness
color c = video.pixels[loc];
float sz = ((percent)*1000/ float(width)) * brightness(video.pixels[loc]) + 20.0;
pushMatrix();
translate(x , y , sz);
println("percent : "+percent);
//translate(x , y , sz+20);
fill(c);
;
noStroke();
//ellipse(0, 0, cellSize , cellSize);
ellipse(x + cellSize/2, y + cellSize/2,sz*brightness(c)/255, sz*brightness(c)/255);
//rect(x + cellSize/2, y + cellSize/2,sz*brightness(c)/255, sz*brightness(c)/255);
//star = createShape();
//star.vertex(0, -16,cellSize, cellSize);
//star.vertex(4, -7,cellSize, cellSize);
//star.vertex(11, -5,cellSize, cellSize);
//star.vertex(5, 2,cellSize, cellSize);
//star.vertex(7, 10,cellSize, cellSize);
//star.vertex(0, 6,cellSize, cellSize);
//star.vertex(-7, 10,cellSize, cellSize);
//star.vertex(-5, 2,cellSize, cellSize);
//star.vertex(-11, -5,cellSize, cellSize);
//star.vertex(-4, -7,cellSize, cellSize);
//star.end(CLOSE);
//shape(star);
popMatrix();
}
}
}
}
public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
}
and I want this code plays after about 10seconds:
- import krister.Ess.*;
- int bufferSize;
int steps;
float limitDiff;
int numAverages=1;
float myDamp=.1f;
float maxLimit,minLimit; - FFT myFFT;
AudioInput myInput;
int audioSensibility;
import processing.video.*; - // Size of each cell in the grid
int cellSize = 6;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
PShape star;
void setup() {-
smooth(); -
Ess.start(this);
bufferSize=512;
myInput=new AudioInput(bufferSize); - // set up our FFT
myFFT=new FFT(bufferSize*2);
myFFT.equalizer(true); - // set up our FFT normalization/dampening
minLimit=.049;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp);
myFFT.averages(numAverages); - // get the number of bins per average
steps=bufferSize/numAverages; - // get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit;
myInput.start();
audioSensibility = 500;
size(1920,900, P3D);
// Set up columns and rows
cols = width/2 / cellSize;
rows = height/2 / cellSize;
colorMode(RGB, 255, 255, 255, 70);
ellipseMode(CENTER); - // Uses the default video input, see the reference if this causes an error
video = new Capture(this, 640, 480);
video.start();
// frameRate(45); - filter(BLUR,15);
}
void draw() {
float percent=max(0,(myFFT.max-minLimit)/limitDiff);
// rect(600,11,50,(int)(198*percent));- if (video.available()) {
video.read();
video.loadPixels();
background(0,0,0);
//filter(BLUR,10);
// Begin loop for columns
for (int i = 0; i < cols;i++) {
// Begin loop for rows
for (int j = 0; j < rows;j++) { - // Where are we, pixel-wise?
int x = i*cellSize + cellSize/2;
int y = j*cellSize + cellSize/2;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image
// Each rect is colored white with a size determined by brightness
color c = video.pixels[loc];
float sz = ((percent)*1000/ float(width)) * brightness(video.pixels[loc]) + 20.0;
pushMatrix();
translate(x , y , sz);
println("percent : "+percent);
//translate(x , y , sz+20);
fill(c);
;
noStroke();
//ellipse(0, 0, cellSize , cellSize);
ellipse(x + cellSize/2, y + cellSize/2,sz*brightness(c)/255, sz*brightness(c)/255);
//rect(x + cellSize/2, y + cellSize/2,sz*brightness(c)/255, sz*brightness(c)/255);
//star = createShape();
//star.vertex(0, -16,cellSize, cellSize);
//star.vertex(4, -7,cellSize, cellSize);
//star.vertex(11, -5,cellSize, cellSize);
//star.vertex(5, 2,cellSize, cellSize);
//star.vertex(7, 10,cellSize, cellSize);
//star.vertex(0, 6,cellSize, cellSize);
//star.vertex(-7, 10,cellSize, cellSize);
//star.vertex(-5, 2,cellSize, cellSize);
//star.vertex(-11, -5,cellSize, cellSize);
//star.vertex(-4, -7,cellSize, cellSize);
//star.end(CLOSE);
//shape(star);
popMatrix();
}
}
}
}
public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
}
Please help me, Thank you.
1