Renaming PDF generated files

Unable to find the answer to this in REFERENCE section.

I have a very simple program to generate random color block overlaps.

Currently set up to record a PDF of each instance when code runs.

How do I generate a new name for the PDF each time code is run (otherwise it’s the same file name each time and overwrites the previous PDF file)?

CURRENT CODE BELOW:

import processing.pdf.*;

float randomH1 = random(300, 400);


void setup() {
  size (400, 600);
  noLoop();
  beginRecord(PDF, "filename.pdf");
}

void draw() {
  background (255);
  noStroke();

  fill(150, 220, random(255), 150);
  rect(0, 0, width, random(150, 275));

  rectMode(CENTER);
  fill(random(255), 185, 185, 150);
  rect(width/2, height/2, width, random(150, 250));

  fill(random(255), 225, 90, 150);
  quad(0, height, width, height, width, randomH1, 0, randomH1);

  endRecord();
}

Many thanks to anyone who can help me with this!
:slight_smile:

1 Like

Is it possible to create a counter that I could attach to the filename?

For example:

beginRecord (PDF, "filename + counter.pdf"

Try this:

beginRecord(PDF, nf(year())+nf(month())+nf(day(),2)+nf(hour(),2)+nf(minute(),2)+".pdf");
}

:slight_smile:

2 Likes

Thank you!!
That works nicely.
Plus I added seconds to be able to save a new named file every second.
:joy:

2 Likes