Skip to content

Instantly share code, notes, and snippets.

@REAS
Last active October 12, 2018 23:41
Show Gist options
  • Save REAS/2cee7383c3dae72253cc583067e6ecad to your computer and use it in GitHub Desktop.
Save REAS/2cee7383c3dae72253cc583067e6ecad to your computer and use it in GitHub Desktop.
Create a PDF file with mouse press
import processing.pdf.*; // Import PDF code
boolean recordPDF = false;
int count = 0;
void setup() {
size(600, 600);
}
void draw() {
if (recordPDF) {
beginRecord(PDF, "line" + nf(count, 4) + ".pdf"); // Start writing to PDF
}
// START PATTERN
background(255);
strokeWeight(10);
for (int y = 100; y < height; y += 100) {
line(mouseX, y, mouseX+200, y); // Draw lines to screen and to PDF
}
// STOP PATTERN
if (recordPDF) {
endRecord(); // Stop writing to PDF
recordPDF = false;
count = count + 1;
}
}
void mousePressed() {
recordPDF = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment