Usage: arcTo(x1, y1, x2, y2, radius)
Description: The arcTo() method will use the current endpoint, endpoint 1 (x1, y1) and endpoint 2 ( x2, y2), and then draw an arc on a circle that is tangent to both sides of the angle and has a radius of radius. The starting point of the arc is the tangent point between the side where the current endpoint is and the circle. The end point of the arc is the tangent point between the side where endpoint 2 (x2, y2) is and the circle, and the arc drawn is the shortest length between the two tangent points. That arc. In addition, if the current endpoint is not the starting point of the arc, the arcTo() method will also add a straight line segment from the current endpoint to the starting point of the arc.
arcTo()绘制
As shown in the picture above, the current endpoint (20,20), endpoint 1 (200,150), and endpoint 2 (20,280) form an angle to draw an arc. The radius is 50 and tangent to the included angle. If the current endpoint is not the starting point of the arc, the arcTo() method will also add a straight line segment from the current endpoint to the starting point of the arc.
The last straight line is drawn by context.lineTo(200,280); and has nothing to do with the arc drawn by arcTo.
stroke(): Draw a defined path
fill(): Fill the current drawing path
I used the following code For the two canvases, the drawing methods are drawCanvas1 and drawCanvas2 respectively, to facilitate comparison of the differences between the two.
stroke()、fill()用法
Syntax: createPattern(image, repetitionStyle)
Description: The createPattern() method is used to create a representation of the image How to repeatedly tile the CanvasPattern object on the current graphic. The parameter image specifies the image used for tiling. This parameter can be an Image object or a Canvas object. The parameter repetitionStyle indicates how the image is repeatedly tiled. Possible values are repeat (repeat tiles in both horizontal and vertical directions, which is also the default value), repeat-x (repeat tiles only in the horizontal direction), repeat- y (repeat tiling only in the vertical direction), no-repeat (tile only once, no repeated tiling).
Look at the example below:
createPattern()用法
Note that the difference between the two lies only in the starting point coordinates of the rectangular area. The first is the starting point coordinate of the canvas (0,0), and the second starting point is (30,30). From the effect point of view, the first image of the second picture is not complete.
Note:The reference starting point for the CanvasPattern object to start tiling the image is not the upper left corner of the graphics we are currently drawing, but the upper left corner of the entire canvas canvas. To be precise, the starting point coordinates of the canvas (0,0 ).
Syntax:
createImageData(width,height); Create an ImageData object with width and height respectively. Returns an ImageData object.
createImageData(imageData); Create a new ImageData object that is the same as the specified imageData object. Returns an ImageData object.
putImageData(imgData,x,y,dirtyX,dirtyY,dirtyWidth,dirtyHeight);
Function: Put the image data (from the specified ImageData object ) placed back on the canvas.
imgData: is the ImageData object that needs to be placed on the canvas.
x: The x coordinate of the upper left corner of the canvas
y: The y coordinate of the upper left corner of the canvas
The four parameters dirtyX, dirtyY, dirtyWidth, and dirtyHeight are optional. If there are no four parameters, the imageData will be changed from x , the y coordinate is completely drawn on the canvas; if there are these four parameters, the dirtyX, dirtyY starting coordinates, width dirtyWidth, and height dirtyHeight of the partial image of the imageData are retained.
getImageData(x,y,width,height);x,y are the x coordinates of the upper left corner where copying starts, width and height are the width and height of the area to be copied. Returns an ImageData object.
putImageData()用法
Syntax: canvas.toDataURL("image/png"); Note that the object is canvas instead of context
Function: Export the canvas canvas as a picture and return the picture data.
canvas绘图
canvas2为使用toDataURL()方法,导出在canvas1元素上绘制的图像。
Notice why the rectangular position of canvas two is different from canvas one?
Because toDataURL() exports the entire canvas, and canvas two is drawn starting from (10, 10).
The above is the detailed content of Detailed explanation of HTML5 canvas (4). For more information, please follow other related articles on the PHP Chinese website!