# Output to PDF every 5 Seconds

**URL:** <https://discourse.processing.org/t/output-to-pdf-every-5-seconds/17125>\
**Category:** Coding Questions\
**Created:** [January 16, 2020, 11:51pm UTC](https://discourse.processing.org/t/output-to-pdf-every-5-seconds/17125 "2020-01-16T23:51:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FutureDays](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FutureDays](https://discourse.processing.org/u/FutureDays)\
**Post date:** [January 16, 2020, 11:51pm UTC](https://discourse.processing.org/t/output-to-pdf-every-5-seconds/17125/1 "2020-01-16T23:51:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 17, 2020, 1:00am UTC](https://discourse.processing.org/t/output-to-pdf-every-5-seconds/17125/2 "2020-01-17T01:00:15Z")

</div>

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

```auto
</> 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](https://processing.org/reference/libraries/pdf/index.html)

---

<div class="post-metadata">

**Author:** ![Abel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/abel/32/3289_2.png) [@Abel](https://discourse.processing.org/u/Abel)\
**Post date:** [January 21, 2020, 4:25pm UTC](https://discourse.processing.org/t/output-to-pdf-every-5-seconds/17125/3 "2020-01-21T16:25:28Z")

</div>

Hey @FutureDays 😊

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.

```auto
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](https://github.com/AbelWondafrash/Periodically-for-Processing) to find a class I made.

Questions are welcome.  
Hope that’s helpful. 🤗
