In H5 we will often use the canvas element to draw graphics. So today we will introduce how to use canvas and under what circumstances canvas can be used. And canvas painting skills
canvas is used to draw graphics on the page
canvas overview:
html5 canvas element is used in conjunction with javascript Draw graphics on the page
Canvas is a canvas, draw paths, rectangles, circles on the canvas...
canvas drawing graphics: ---》javascript drawing
Canvas itself does not have the drawing ability, drawing work All are done in javascript*****
js to get the element
element.getContext("2d") html5's built-in object, which can be used to draw 2d graphics. Methods for drawing rectangles, paths, circular characters, etc.
cxt.fillStyle = "#ff0000"; //Draw fill color
cxt.fillRect(25,10,150,75);//x, y,w,h determine the shape 25,10 starting point coordinates
Note: canvas is not supported
Your browser does not support canvas
Drawing straight lines and rectangles
Line lines:
cxt.moveTo(10,10); Original starting point
cxt.lineTo(150,50); The end point of the original starting point is the starting point of the next straight line of the same 2D graphic
cxt.stroke(); Output
The above is the detailed content of Common drawing techniques in Canvas in HTML5. For more information, please follow other related articles on the PHP Chinese website!