enter image description herehttps://github.com/sarang997/simulation1 Here is the simulation I am working on. You can try running the html file for it to work. There are circles colliding with each other in the simulation. Whenever a red circle collides with the green circle it changes the color of the green circle to red. Now what I want is as soon as the circle turns red I want a timer which changes its color to blue after n seconds. I am not able to achieve this.
There is a section in the shapes.js file where collision between the circles is detected and thats where I am changing the colors and thats exactly where I want the timer to start. (line 104 and 110 in shapes.js file)
Here is my solution to the problem you can loop it as well if you want the circle to continue changing colors (here replaced by console.log). N is here equal to seconds, it's multiplied by 1000 as setTimeout uses milliseconds by default.
function changeColor(seconds) {
setTimeout(function () {
console.log('Here the circle would change color.');
}, seconds*1e3);
}
changeColor(3)