restart sketch after a few minutes
in
Programming Questions
•
2 years ago
Hi
I would like to know if someone can help me with this. I would like restart the sketch below after a certain time period, but can't seem to figure out how to do so. I'm able to restart it after key pressed, but not automatically after a certain time period. The sketch also saves to pdf after it stops. How can I have it saved to different file names each time it restarts?
here's the sketch:
void setup() {
size (1024, 768);
beginRecord(PDF, "Sounds_01.pdf");
smooth();
noFill();
background(#ffffff);
frameRate(15);
Ess.start(this);
myInput=new AudioInput();
myFFT=new FFT(512);
myInput.start();
for (int i=spektrum_min; i<spektrum_max; i++) {
frequenzArray[i] = new frequenz();
}
}
void draw() {
ps=new SimplePostscript(this);
ps.open("abstract01.ps", 0,0, width,height);
ps.isOpen=true;
if (speel) {
myFFT.getSpectrum(myInput);
for (int i=spektrum_min; i<spektrum_max; i++) {
float temp=min(10, max(0, (myFFT.spectrum[i]*8000)));
frequenzArray[i].teken(temp, i);
}
}
}
class frequenz {
float x;
float y;
float x2;
float y2;
frequenz() {
x = x_begin;
y = y_begin;
}
void teken (float waarde, int range) {
y2 = lengte * tan(radians((waarde)*100)+(spektrum_max * range))%6;
x2 = lengte * tan(radians((waarde)*100)+(spektrum_min * range))%6;
if (waarde > threshold) {
doStroke(0,0,0,8);
doLine (x, y, x+x2, y+y2);
}
else {
doStroke(150,20,240,5);
doLine (x, y, x+x2, y+y2);
}
x = x+x2;
y = y+y2;
}
}
void doStroke(float r, float g, float b, float w) {
stroke(r,g,b);
strokeWeight(w);
if(ps.isOpen) ps.setrgb((int)r, (int)g, (int)b); ps.setlinewidth((int)w);
}
void doLine(float x,float y, float x2,float y2) {
line(x,y,x2,y2);
if(ps.isOpen) {
ps.moveto(x,height-y);
ps.lineto(x,height-y);
ps.stroke();
}
}
void audioInputDone(AudioInput in) {
speel = false;
ps.close();
ps.isOpen=false;
endRecord();
}
public void stop() {
Ess.stop();
super.stop();
}
I would like to know if someone can help me with this. I would like restart the sketch below after a certain time period, but can't seem to figure out how to do so. I'm able to restart it after key pressed, but not automatically after a certain time period. The sketch also saves to pdf after it stops. How can I have it saved to different file names each time it restarts?
here's the sketch:
void setup() {
size (1024, 768);
beginRecord(PDF, "Sounds_01.pdf");
smooth();
noFill();
background(#ffffff);
frameRate(15);
Ess.start(this);
myInput=new AudioInput();
myFFT=new FFT(512);
myInput.start();
for (int i=spektrum_min; i<spektrum_max; i++) {
frequenzArray[i] = new frequenz();
}
}
void draw() {
ps=new SimplePostscript(this);
ps.open("abstract01.ps", 0,0, width,height);
ps.isOpen=true;
if (speel) {
myFFT.getSpectrum(myInput);
for (int i=spektrum_min; i<spektrum_max; i++) {
float temp=min(10, max(0, (myFFT.spectrum[i]*8000)));
frequenzArray[i].teken(temp, i);
}
}
}
class frequenz {
float x;
float y;
float x2;
float y2;
frequenz() {
x = x_begin;
y = y_begin;
}
void teken (float waarde, int range) {
y2 = lengte * tan(radians((waarde)*100)+(spektrum_max * range))%6;
x2 = lengte * tan(radians((waarde)*100)+(spektrum_min * range))%6;
if (waarde > threshold) {
doStroke(0,0,0,8);
doLine (x, y, x+x2, y+y2);
}
else {
doStroke(150,20,240,5);
doLine (x, y, x+x2, y+y2);
}
x = x+x2;
y = y+y2;
}
}
void doStroke(float r, float g, float b, float w) {
stroke(r,g,b);
strokeWeight(w);
if(ps.isOpen) ps.setrgb((int)r, (int)g, (int)b); ps.setlinewidth((int)w);
}
void doLine(float x,float y, float x2,float y2) {
line(x,y,x2,y2);
if(ps.isOpen) {
ps.moveto(x,height-y);
ps.lineto(x,height-y);
ps.stroke();
}
}
void audioInputDone(AudioInput in) {
speel = false;
ps.close();
ps.isOpen=false;
endRecord();
}
public void stop() {
Ess.stop();
super.stop();
}
1