Like painting, you first have to have a pen, this pen has a thickness, color, you can draw a straight line, you can draw the curve, then we will start from a location point pen, and then ends at another location point. Such . you can draw a line - the following steps:
1. Create a path: ctx.beginPath () , represents picked up a brush ready to open the picture.
2. The first point to move the pen ready to draw: ctx.moveTo ();
3. Draw Path: ctx.lineTo ();
4. End Path drawing: ctx.closePath ();
5. Draw a path, the path is added to the style, such as color and thickness, etc.: ctx.stroke ()
function Draw () { var Canvas = document.getElementById ( 'canv' ); IF (canvas.getContext!) return ; var CTX = canvas.getContext ( "2D" ); // open path drawing ctx.beginPath (); / / determining a path starting point ctx.moveTo (30, 30 ); // draw a path ctx.lineTo (280, 280 ); // end path drawn with ctx.beginPath () corresponding to ctx.closePath (); // stroke, or "presentation" ctx.stroke () } Draw ();