# Save the canvas at a frequency keeping all the images

**URL:** <https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559>\
**Category:** Beginners\
**Created:** [November 16, 2021, 6:50pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559 "2021-11-16T18:50:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hiram-Belgium](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hiram-belgium/32/4874_2.png) [@Hiram-Belgium](https://discourse.processing.org/u/Hiram-Belgium)\
**Post date:** [November 16, 2021, 6:50pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/1 "2021-11-16T18:50:29Z")

</div>

Hello, I am a beginner who knows very little about programming.  
I would like to know how to save the canvas at regular intervals, for example every 5 seconds … But also obviously keep all the images. Example image1-5sec … image2-10sec … image3-15sec … etc. Hope my question is understandable! Thanks I managed to save with a save canvas in the draw () function but not with a timing … Thanks

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 16, 2021, 11:29pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/2 "2021-11-16T23:29:29Z")

</div>

Roughly

```auto

if(millis()-timer>5000){
save("img"+nf(i,10)+".jpg");//see reference for nf()
i++;
timer=millis();
}

```

Make timer and i a global variable;  
int timer;  
int i;

---

<div class="post-metadata">

**Author:** ![Hiram-Belgium](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hiram-belgium/32/4874_2.png) [@Hiram-Belgium](https://discourse.processing.org/u/Hiram-Belgium)\
**Post date:** [November 17, 2021, 9:54am UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/3 "2021-11-17T09:54:58Z")

</div>

Hello. I am really a beginner and I will sound stupid to you! Thank you for your help but I am having several problems.  
Declaring variables … int doesn’t work for me, I had to put let instead. Image saves well but only once, so I think I’m in the wrong place to insert it? Thank you

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 17, 2021, 10:14am UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/4 "2021-11-17T10:14:18Z")

</div>

You need to have my code block in draw()

It will save every 5 seconds

---

<div class="post-metadata">

**Author:** ![Hiram-Belgium](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hiram-belgium/32/4874_2.png) [@Hiram-Belgium](https://discourse.processing.org/u/Hiram-Belgium)\
**Post date:** [November 17, 2021, 11:09am UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/5 "2021-11-17T11:09:29Z")

</div>

Hello I think the variables went wrong with me because it only saves an image once and the name is always the same !? So the variable i does not increment and also timer I think ??? Difficult problem for a novice … Can there be an error coming from index.html?

 ![2021-11-17_120228](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aa2a5f89bfdfc6ca0f63121d85df94d1170716f0.jpeg)  
 ![2021-11-17_120303](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e2acd001fd6d6892493d22cf037bb390a02d3221.jpeg)  
 ![2021-11-17_120346](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d2ee50c0e06c1732ad06b0f8ac3d9d490c1ad7af.jpeg)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 17, 2021, 2:01pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/6 "2021-11-17T14:01:03Z")

</div>

5 seconds might be too high… try 360 or so

How long does the whole sketch run?

Please remember that your screen is not updated during the for loop but only at the end of draw()

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 17, 2021, 2:11pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/7 "2021-11-17T14:11:39Z")

</div>

You have variable i twice

Should not be a problem but still try to replace my i with i2 please (in 3 places in the code)

I can’t really help you, I am on a journey

---

<div class="post-metadata">

**Author:** ![Hiram-Belgium](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hiram-belgium/32/4874_2.png) [@Hiram-Belgium](https://discourse.processing.org/u/Hiram-Belgium)\
**Post date:** [November 17, 2021, 4:11pm UTC](https://discourse.processing.org/t/save-the-canvas-at-a-frequency-keeping-all-the-images/33559/8 "2021-11-17T16:11:07Z")

</div>

I am asking for help as a novice because something is happening to me that I am unable to understand !?  
I program with visualstudio code. The program does not run properly! IF I LAUNCH THE PROGRAM IN DEBUG MODE it runs perfectly! Please how is this possible? THANK YOU
