Creating an animation class
As per Wikipedia, animation is the process of creating the illusion of motion and shape change by means of the rapid display of a sequence of static images that minimally differ from each other. So we draw a canvas, clear it, then draw it again with minimal changes, again clear it, again draw it with some more changes, again clear it, and this cycle continues.
So the steps for animation can be given as:
Initialize.
Clear the canvas.
Draw on the canvas.
Update the drawing with minimum changes.
Perform the previous three steps (2, 3 4) in a loop.
These steps need to be called rapidly, and for this we use a function named requireanimationframe
(callback).
This method tells the browser that you wish to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint (redraw). The method takes as an argument a callback method to be invoked before the repaint (redraw).
As browsers and computer hardware are not created...