Save the canvas at a frequency keeping all the images

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

1 Like


save("img"+nf(i,10)+".jpg");//see reference for nf()

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

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

1 Like

You need to have my code block in draw()

It will save every 5 seconds

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?


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()

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

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

1 Like