Output to PDF every 5 Seconds

Hello,

I am a total newbie to Processing but am loving the learning.

I have a question, how do I write a line of code that outputs a PDF to a folder on the desktop every 5 seconds.

I have placed my code here for reference:

float x = 600;
float y = 300;

float xSpeed = 30;
float ySpeed = 10;

void setup () {
size (1800, 1280);
}

void draw (){
fill (random (255), random (255), random (255));

x += xSpeed;
if (x > width || x < 0) {
xSpeed *= -1;
}

y += ySpeed;

if (y > height || y < 0) {
ySpeed *= -1;
}

ellipse (x,y,50,50);
}

Looking forward to a reply.

Best,

Robert

please format your code posting here at forum
( topic editor )
by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.
or select the already pasted “code” and use [ctrl][shift][c]

thank you.


also we recommend that the code from processing IDE ( PDE )
is formatted there first, like with /Edit/Auto Format/ or [ctrl][t]


now we need you to REPAIR your above CODE POSTING,
not make a new / better post.
( just think about the hundred people opening your topic in the future )


there are several ways, play with it

https://processing.org/reference/libraries/pdf/index.html

Hey @FutureDays :blush:

If you have an experience using the function delay () then you know that it freezes everything that the program is doing then proceeds to the following code after a certain amount of time.

Surely this is not so useful most of the time. Instead, I recommend taking a look at the function millis () instead. You can learn more about it from the Processing references but for now, know that it returns the number of milliseconds since the starting of the program. This can be turned into use as you’ll see below.

Here I’ve crafted you a very simple way of implementing it.

long lastTime;
int patience = 5000; // 5000 milliseconds > 5 seconds

void setup () {
  
}

void draw () {
  if(millis () - lastTime > patience) {
    // Do something you want to be done periodically here
    print ("Horray!");

    // Update lastTime so that it can serve as a new reference time
    lastTime = millis ();
  }
}

After you got a hang of that, you can create your own class to keep things neat. Or click here to find a class I made.

Questions are welcome.
Hope that’s helpful. :hugs: