PDF problem
in
Core Library Questions
•
2 years ago
Hi, i would like to write a PDF whenever i press the alt key with different numbered PDF's. In the moment i just get one PDF because i start the recording in setup. But when i write the code in draw () it writes too much PDF's and i cannot open them. I always have this problem, when the changings are not made in draw (). How can i do this better?
import processing.pdf.*;
boolean recordPDF = false;
PFont font;
String letter = "A";
void setup () {
size (800, 800);
background (255);
if (recordPDF == false) {
beginRecord (PDF, "buchstaben####.pdf");
println("recording started");
recordPDF = true;
}
font = createFont ("BirchStd", 10);
textFont (font);
textAlign (CENTER, CENTER);
}
void draw () {
}
void mouseMoved () {
background (255);
fill(mouseX-400, random (255), random (255), 100);
textSize ((mouseX-400)*5+1);
text (letter, width/2, mouseY);
}
void mouseDragged () {
fill(mouseX-400, random (255), random (255), 100);
textSize ((mouseX-400)*5+1);
text (letter, random (width), mouseY);
}
void keyReleased() {
if (keyCode == CONTROL) saveFrame(timeStamp()+"_##.png");
if (key != CODED && (int)key > 32) {
letter = str(key);
}
if (keyCode==ALT) if (recordPDF) {
println("recording stopped");
endRecord();
recordPDF = false;
}
}
// timestamp
String timeStamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
1