Skip to content

Instantly share code, notes, and snippets.

@takawo
Created December 27, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takawo/3e66b85c748e5a57cd77fe93de615832 to your computer and use it in GitHub Desktop.
Save takawo/3e66b85c748e5a57cd77fe93de615832 to your computer and use it in GitHub Desktop.
import processing.pdf.*;
import java.util.Calendar;
boolean savePDF = false;
void setup() {
//settings();
}
void settings() {
int dpi=72;
float width_mm=210;
float height_mm=297;
int width_px=int(width_mm*0.03937*dpi);
int height_px=int(height_mm*0.03937*dpi);
size(width_px, height_px);
}
void draw() {
if (savePDF) beginRecord(PDF, timestamp()+".pdf");
colorMode(HSB, width, height, 100);
// write some code...
if (savePDF) {
savePDF = false;
endRecord();
}
}
void keyPressed() {
if (key=='s' || key=='S') saveFrame(timestamp()+"_##.png");
if (key=='p' || key=='P') savePDF = true;
}
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment