9.5: JavaScript setInterval() Function – p5.js Tutorial




This video covers the setInterval() function in JavaScript in the context of p5.js. setInterval() allows you to execute a given function every N milliseconds.

https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval

All examples: https://github.com/shiffman/Video-Lesson-Materials
Solution to exercise mentioned:
https://github.com/shiffman/Video-Lesson-Materials/blob/master/code_p5.js/9.2b_p5.js_setInterval/sketch.js

Contact: https://twitter.com/shiffman

Next video: https://youtu.be/-jysK0nlz7A

All JavaScript/p5.js videos: https://www.youtube.com/user/shiffman/playlists?shelf_id=14&view=50&sort=dd

Help us caption & translate this video!

http://amara.org/v/Qbtb/

Original source


9 responses to “9.5: JavaScript setInterval() Function – p5.js Tutorial”

  1. hello very nice explanation, i have set xml api with ajax get method,and set interval function to get latest data every 15 second ,now my question is every thing working fine in window linux android ,,but when i load it on iphon it,s refresh the whole page after 15 second and i dont want that it,s should run on background,,so please help me what i need to do ,here is the link :http://liveodd.co.uk/home/Livescore

  2. Hey Dan, think you can help me? I want to make for a program of mine (a bot for Discord) a constant update on what "game" it's playing. Most of the bots use the games to show how to use the bot by setting it to their help command. However, I made a little customizable part, and I want my bot to check, let's say, every second if it changed. I'm not sure how to make setInterval do that, do you know by accident? If you need the code, just reply and I'll paste it.

  3. This video is amazing! Daniel, If you've got a spare moment i'd love your help! I've got my simulation running by clicking on a button which sets off setInterval. When I click the button again it runs two simulations which makes canvas freak out. How can I clear the first simulation with the button then make the next simulation run over it? Thank in advance man!

  4. Hi Daniel, could you explain how the timer stops when you click the button again. I see your using an if else statement but how does it know to stop the timer? example) if ( !interval ){ interval = setInterval(); } else { clearInterval ( interval ); interval = false; }

Leave a Reply