import processing.pdf.*; import java.util.Calendar; import controlP5.*; boolean savePDF = false; ControlP5 controlP5; void setup() { size(720, 720); if (frame != null) { frame.setResizable(true); } //noCursor(); setGUI(); } void setGUI() { controlP5 = new ControlP5(this); controlP5.addButton("Save",1,70,10,60,20); } void draw() { // this line will start pdf export, if the variable savePDF was set to true if (savePDF) beginRecord(PDF, timestamp()+".pdf"); colorMode(HSB, 360, 100, 100); rectMode(CENTER); noStroke(); background(mouseY/2, 100, 100); fill(360-mouseY/2, 100, 100); rect(360, 360, mouseX+1, mouseX+1); // end of pdf recording if (savePDF) { savePDF = false; endRecord(); } } void controlEvent(ControlEvent theEvent) { if(theEvent.isController()) { // if(theEvent.controller().name()=="Save") { if(theEvent.controller().getName()=="Save") { savePDF = true; } } } 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); }