import processing.pdf.*; import java.util.Calendar; import controlP5.*; boolean savePDF = false; ControlP5 controlP5; void setup() { size(720, 720); background(0); if (frame != null) { frame.setResizable(true); } colorMode(HSB, 360, 100, 100); rectMode(CENTER); noStroke(); setGUI(); //fullScreen(); //noCursor(); //frameRate(30); } /** * mouseX, mouseY current position of the mouse * pmouseX, pmouseY previous position of the mouse * * width, height width and hight of the window * * line(x1, y1, x2, y2) line from (x1, y1) to (x2, y2) * rect(x, y, width, height) rectangle * ellipse(x_c, y_c, width, height) ellipse * triangle(x1, y1, x2, y2, x3, y3) triangle * point(x, y) point of size 1px * * stroke(35) color of stroke in grayscale * stroke(25, 25, 25) color of stroke in given color scale (RGB/HSB) * noStroke() * strokeWeight(3) width of stroke in px * fill(35) / fill(35, 35, 35) fill color in grayscale / color scale * noStroke() * */ void draw() { // this line will start pdf export, if the variable savePDF was set to true if (savePDF) beginRecord(PDF, timestamp()+".pdf"); // overdraw each frame with a new background 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(); } } // ----- User interactivity ----- void keyPressed() { if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png"); if (key == 'p' || key == 'P') savePDF = true; } void mousePressed() { } // ----- ControlP5 GUI ----- void setGUI() { controlP5 = new ControlP5(this); controlP5.addButton("Save",1,70,10,60,20); } void controlEvent(ControlEvent theEvent) { if(theEvent.isController()) { // if(theEvent.controller().name()=="Save") { if(theEvent.controller().getName()=="Save") { savePDF = true; } } } // ----- Help methods ----- String timestamp() { Calendar now = Calendar.getInstance(); return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now); }