In addition, it is also used to draw other polygons.
Draw complex SVG shapes
Used to draw complex shapes, the path to draw is defined in attribute d = "way - drawing command"
The commands used in attribute d are:
M: move the drawing point to the x and y coordinates (M xy).
L: draw from the current point to the point x, y (L xy).
H: Draw a horizontal line from the current point to the point where x (H x) is coordinates.
V: Draw a vertical line to the point with the y coordinate (y y).
C: draw cubic-bezier curve from current point x0, y0 to point x, y. the beginning of the tangent curve to the straight line x0, y0, x1, y1, the second point of the tangent curve to the wall x, y, x2, y2 C x1 y1, x2 y2, x, y.
S: draw a smooth curve from the current point x0, y0 to the point x, y in which the first point tangent to the line x0, y0, x2, y2 S x2 y2, x y.
Q: Draw cubic-bezier curves from the current point x0, y0 to point x, y. The beginning of the tangent curve to the straight line x0, y0, x1, y1 is the second point of the tangent curve to the wall x, y, x1, y1 C x1 y1, x y.
T: draw cubic-bezier curves, from current point to point x, y (T xy).
The comparison table below shows some important differences between Canvas and SVG:
CANVASSVG
Canvas draws 2D graphics with JavaScript.
Canvas is displayed as pixels standing side by side.
In canvas, when an image has been drawn, it will not be remembered by the browser. If the position of the image wants to change, the whole image will need to be re-drawn including the objects around the graphic object.
Depends on the resolution
No support in handling events
The ability to create images for text is not good
You can save the image after drawing it as .png or .jpg
Very suitable for graphics games
SVG describes 2D graphics in XML
SVG is built on XML so all components are available in SVG DOM. You can use javascript to handle the above events for SVG elements.
In SVG, each drawn image is stored as an object. If the properties of an SVG object change, the browser will automatically return the result.
Not dependent on resolution
Support in handling events
Suitable for wide image building applications (Google Maps)
Build images slowly if graphics are complex (Everything using multiple DOMs is slow)
Not suitable for game applications
Okay, so we've finished learning how to use HTML5 graphics drawing canvas and. Hopefully the lesson will be useful for you. Let's wait for the next lesson with TipsMake.