How to draw a star by using canvas HTML5?

Drawing on the HTML canvas is to be done with JavaScript. Use the HTML DOM Method getElementById() and getContext() before drawing on the canvas. To draw a star in HTML, use the canvas element.

With canvas, use the lineTo() method to draw a star. The lineTo() method includes x and y parameter values, which positions the lines to help you in drawing.

To draw canvas on HTML document:

Example

You can try to run the following code to draw a star using HTML5 canvas



   
      HTML5 Canvas Tag
   
   
      
      
   

Output

Updated on: 2021-12-16T09:52:08+05:30

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements