Core Concept of Delayed Circle Drawing Using JavaScript
In this code, the <canvas> element of HTML 5 and the setTimeout method of JavaScript are used.
Working of this Program
- When the user clicks on the “Draw Circle After 3 Seconds” button, an alert is shown, which triggers the setTimeout(drawCircle, 3000) method.
- After 3 Seconds (3000 milliseconds), the drawCircle() method is executed.
- Then the drawCircle method uses the canvas context and draws the circle.
Why is it used?
- To control the graphics, shapes, and animations, the Canvas API is used.
- With the help of setTimeout, any code can be executed asynchronously.
Real-life Applications
- Interactive games: With the help of canvas and shapes, 2D & 3D games like snake game, physics sandbox, etc. are built, and according to the time delay, the various objects or characters are rendered.
- Data Visualization & Charts: To draw animated charts like pie chart, bar charts etc. are rendered with the help of this canvas.
- Drawing tools and whiteboards: To draw shapes in Paint or any design web app like Canva.
Benefits of this Program
- High-Performance Graphics: Uses the canvas shapes the animation perform better than div or span elements.
- Precise Control: With the help of (x, y, radius, angles), the shapes can be drawn precisely.
