Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

PDF Export on mousePressed?

$
0
0
Hi, I'm new to Processing and programing in general. My apologies if this has been addressed elsewhere, but I couldn't find what I needed in the reference or other forums.  I have a basic program that is structured like this:
  1. void setup () {
  2.   // set size/background
  3. }

  4. void draw () {
  5.   // draw random shapes
  6.   noLoop ();
  7. }

  8. void mousePressed() {
  9.   saveFrame ("rs-###.jpg");
  10. }

  11. void keyPressed() {
  12.   setup();
  13.   redraw();
  14. }
The idea is that the program draws a set of random shapes.  If I press a key on the keyboard, it resets and draws a new set of random shapes.  If I get something I like, I click the mouse and it saves a JPEG.

What I'd like to do now is get a PDF in place of a JPEG when I click the mouse.  But all I can figure out is this:
  1. import processing.pdf.*;

  2. void setup () {
  3.   // set size/background
  4.   beginRecord(PDF, "rs-###.pdf");
  5. }

  6. void draw () {
  7.   // draw random shapes
  8.   noLoop ();
  9.   endRecord();
  10. }

  11. void mousePressed() {
  12.   saveFrame ("rs-###.jpg");
  13. }

  14. void keyPressed() {
  15.   setup();
  16.   redraw();
  17. }
which saves a PDF every time the draw function is run.  The problem is that I only want to save a PDF after I see what the draw function does (and would like to trigger the save with mousePressed), but it seems that I need to start recording before the draw function even runs to capture the results.  Any help would be greatly appreciated!

Thanks,

Jeff

Viewing all articles
Browse latest Browse all 1768

Trending Articles