What is the correct way to clear the canvas animation on click of a button and restart it?
You need to start the canvas animation on the click of the button, when you click the button again, the animation should be reset and repeated again (tuggle effect). In the example, I did so, however, on my click, the function is called many times without clearing the old canvas, which by itself affects the speed (fps) of the animation. How to do it right?
To place the code, please use CodePen or similar tool. Thanks you!