SVG basics | SVGPATH element-

Source: Internet
Author: User
The path element of SVG is used to define complex graphics. It can be used in combination with straight lines and curves to create various irregular images. The path element is the most complex of SVG basic images. It also takes a bit of hard work to grasp and understand it ....,.


SVG Elements are used to define complex graphics. It can be used in combination with straight lines and curves to create various irregular images. Elements are the most complex of SVG basic images. It also takes a hard time to master and understand it. Let's look at an example:



  1. Style = "stroke: #660000; fill: none;"/>


The returned results of the code above are as follows:

We can see that the SVG image contains a curve and two straight lines, and the second line is a distance between the first line immediately.

All of these plotting work is on The d attribute is used in the element. The property contains some commands for drawing. In the above example, the M command represents the meaning of "Move. Command A represents an arc ). The L command represents "Line ). These commands are executed by a "virtual paint brush", which can move and draw images.

   Set and move virtual paint brushes

In The first command in the d attribute of an element is always a move command. Before you draw a graph, you must move the virtual paint brush to a certain position. Move the paint brush using the M command. See the following example:



  1. Style = "stroke: #660000; fill: none;"/>

In the preceding example, the virtual paint brush is moved to the coordinates (50, 50. Then the following draw command will start to draw the image from this position.

   Straight Line

The line command is Element is the simplest command. Use the L or l command to draw a straight line. The following is an example:



  1. Style = "stroke: #660000; fill: none;"/>

In the preceding example, a straight line is drawn from the coordinates of (50, 50), and the end point of the line is at (100,100. The returned results are as follows:

What is the difference between linear commands L and l? The L command of the size draws a straight line to a point in the absolute position, while the l command in lower case draws a straight line to a point in the relative position. A relative point is the coordinate of the Point drawn from the virtual paint brush plus the coordinate given by the l command. Why not? It doesn't matter. Let's take an example: if the starting position of the virtual paint brush is (50, 50) and the coordinate given by the l command is (100,100), then the straight line will start from (50, 50) start to draw the position and draw it to the position (50 + 100, 50 +. If the L100 and 100 commands are used, a straight line is drawn from the position (50, 50) to the position (100,100.

Path graphics always start from the last position of the virtual paint brush to draw a new coordinate point. Each draw command has an end point. After these draw commands are executed, the virtual paint brush locates at the ending point determined by these commands. The next draw command starts from these points.

   Arc

Use Element to draw an arc using the or a command. The size and lower case commands have the same meaning as line commands. See the following example:



  1. Style = "stroke: #660000; fill: none;"/>


The returned results of the code above are as follows:

In this example, an arc is drawn from (50, 50) and the end point is at (100,100 ).

The arc radius is determined by the two values of the command. The first parameter is rx, the radius in the horizontal direction, and the second parameter is ry, the radius in the vertical direction. If rx and ry are set to the same value, a circular arc is generated. If rx and ry are set to different values, an elliptical arc is generated. In the preceding example, the rx value is 30, and the ry Value is 50.

The third parameter on the command is x-axis-rotation. This parameter is used to set the rotation on the X axis of the arc. You do not need to change this parameter. The default value is 0.

The fourth and fifth parameters are large-arc-flag and sweep-flag, respectively. They are two signs. We know that two different arcs can be drawn from point A to point B. One is large and the other is small. Large-arc-flag is used to determine whether to draw the larger arc or the smaller one.

Here is an example. The following shows four identical arcs using different large-arc-flag and sweep-flag values:



  1. Style = "stroke: # cccc00; stroke-width: 2; fill: none;"/>


  2. Style = "stroke: # ff0000; stroke-width: 2; fill: none;"/>


  3. Style = "stroke: #00ff00; stroke-width: 2; fill: none;"/>


  4. Style = "stroke: # 0000ff; stroke-width: 2; fill: none;"/>


Let's take a look at the results:

The four different arcs are drawn from () to (60, 70 ). Their rx and ry values are equal, so they are a positive circular arc. The four arcs are respectively a long arc, a short arc, and two images of the first two arcs. The large-arc-flag attribute determines whether to draw a long or short arc. The sweep-flag determines whether to mirror the arc along the straight line from the start point to the end point. In fact, the sweep-flag controls the direction of the arc and draws the arc clockwise or counterclockwise. The result is an "image" effect.

The first arc drawn by the code above is a yellow arc. Its large-arc-flag attribute is set to 0, which means that smaller arcs will be drawn. Sweep-flag is also set to 0, which means no image arc is taken. The results returned by the yellow Arc are as follows:

The second drawn arc is a red arc. Its large-arc-flag attribute is set to 1, which means the larger arc will be drawn. The sweep-flag attribute is set to 0, which means no image arc is taken. The returned results of the red Arc are as follows:

The third drawn arc is a green arc. It is an image of a red arc (an image is made in a straight line formed along the starting and ending points of the arc ). We can see that its sweep-flag attribute is set to 1.

The fourth arc is a blue arc. It is an image of a yellow arc because its sweep-flag attribute is set to 1.

   Beaz Curve

Use The element can also draw a secondary beam curve. Use the Q or q command to draw a quadratic beam curve. The Q command of the case-sensitive version is the same as that of the line. Commands of the large or small version indicate that the ending point is in the absolute coordinate system. Commands of the lower-case version indicate that the end point is in the relative coordinate system (relative to the start point ). The following is an example of a quadratic Beitz curve:


  1. Style = "stroke: #006666; fill: none;"/>


The returned results are as follows:

In the preceding example, a quadratic beam curve is drawn from (50, 50) to (100,100), and the position of the control point is (50,100. The control point is two parameters set by the Q command.

If you have used some vector image editing software, such as Adobe Illustrator, you will understand what is the Beitz curve and control point. On a point in a vector chart, we can see that there are two control controllers on this point. By dragging these two controllers, we can adjust the radians of this point.

Control Points can stretch curves like magnets. The closer the control point is to the arc, the smoother the arc. The control point is month away from the arc, and the arc is stretched. The following are examples of control points at different locations:

In fact, if you draw a straight line from the start point to the control point, draw a straight line from the control point to the end point, and then connect the centers of the two straight lines, the line is tangent to the ARC. The following image is shown:

   Cubic Beitz Curve

The commands for drawing the Three-Byz curve are C and c. The cubic Beitz curve is the same as the quadratic Beitz curve, but it has two control points. The end point of an upper-case command uses an absolute coordinate system, and the end point of a lower-case command uses a relative coordinate system (relative to the start point ). The following is an example of a cubic Beitz curve:


  1. Style = "stroke: #006666; fill: none;"/>


The following is the returned result, and two control points are also drawn.

You can use a cubic Beitz curve to draw complex curves. The following are some examples:

   Closed Path

   The element has a shortcut command for the closed path. A closed path refers to the link from the last draw point to the start point. This command is Z (or z, Which is case-insensitive ). The following is an example:


  1. Style = "stroke: #006666; fill: none;"/>


The returned results of the above Code are as follows:

   Combined with various commands

We can Integrate various draw commands. The following is an example:


  1. Style = "stroke: #006666; fill: none;"/>


The above Code draws a straight line, an arc and a secondary Beitz curve, and finally uses the Z command to close the path. The result is as follows:

   Fill path

We can use the fill attribute of CSS to fill the path. See the following example:


  1. Style = "stroke: # Skip cc;
  2. Stroke-width: 2px;
  3. Fill: # ccccff; "/>


The result of the code above is as follows:

Duplicate commands

If you repeatedly use the same command multiple times, you can omit it and write only the following parameters. For example:


  1. Style = "stroke: #000000; fill: none;"/>


In the preceding example, the l command is used repeatedly to draw a straight line. Except for the first l command, other commands can be omitted. The result is as follows:

  PATH command

SVG is listed below Command that can be used by the virtual paint brush of an element. Commands are usually used to parse the parameter coordinates into absolute coordinates. Commands in lower case usually resolve the parameter coordinates to relative coordinates.

Command Parameters Name Description
M X, y Moveto Move the virtual paint brush to the specified (x, y) Coordinate. Only move the paint.
M X, y Moveto Move the virtual paint brush to the specified (x, y) Coordinate. The coordinate is relative to the coordinate of the current paint brush.
L X, y Lineto Draws a straight line from the position of the current paint brush to the specified (x, y) Coordinate
L X, y Lineto Draws a straight line from the position of the current paint brush to the specified (x, y) Coordinate. The (x, y) coordinate is the point relative to the petal position.
H X Horizontal lineto Draws a horizontal line to the x coordinate point specified by the parameter. The y coordinate is the y coordinate of the paint brush.
H X Horizontal lineto Draws a horizontal line to the x coordinate point specified by the parameter (current x + specified x). The x coordinate is relative to the x coordinate of the current paint brush.
V Y Vertical lineto Draw a vertical line from the current position to the y coordinate specified by the Parameter
V Y Horizontal lineto Draws a vertical line from the current position to the y coordinate specified by the parameter. The y coordinate is relative to the y coordinate of the current paint brush.
C X1, y1 x2, y2 x, y Curveto Draw a cubic beam curve from the current paint position to the coordinates specified by the parameter (x, y. X1, y1, x2, and y2 are the start and end control points of the Curve. They are used to control the radians of the curve.
C X1, y1 x2, y2 x, y Curveto The size of the C command is the same, but the coordinates are relative to the coordinates of the paint brush.
S X2, y2 x, y Shorthand/smooth curveto Draw a cubic beam curve from the current paint position to the coordinates specified by the parameter (x, y. X2, y2 is the end control point. The Start Control Point and the end control point of the previous curve are the same.
S X2, y2 x, y Shorthand/smooth curveto It is the same as the size of the S command, but the coordinate is the coordinate point relative to the current brush.
Q X1, y1 x, y Quadratic beaz Curve Draw a secondary beam curve from the current paint position to the coordinates specified by the parameter (x, y. X1 and y1 are control points used to control the curve radians.
Q X1, y1 x, y Quadratic beaz Curve It is the same as the Q command, but the coordinate is the coordinate point relative to the current brush.
T X, y Smooth quadratic Beitz Curve Draw a secondary beam curve from the current paint position to the coordinates specified by the parameter (x, y. The control point is assumed to be the last control point used
T X, y Smooth quadratic Beitz Curve It is the same as the T command, but the coordinate is the coordinate point relative to the current brush.
A Rx, ry x-axis-rotation large-arc-flag, sweepflag x, y Elliptical Arc Draw an elliptical arc from the current paint position to the coordinates specified by (x, y. Rx and ry are the horizontal and vertical radius of the elliptical arc respectively. X-axis-rotation specifies the degree to which the arc line rotates around the x axis. It works only when the rx and ry values are different. Large-arc-flag is a large arc flag with a value of 0 or 1. It is used to determine whether to draw a large arc or a small arc. The sweep-flag is used to determine the direction of the Arc Drawing.
A Rx, ry x-axis-rotation large-arc-flag, sweepflag x, y Elliptical Arc It is the same as the upper-case A command, but the coordinate is the coordinate point relative to the current paint brush.
Z None Closed Path Draw a straight line from the end point to the start point, close the path
Z None Closed Path Draw a straight line from the end point to the start point, close the path

This article copyright belongs to the jQuery house, reproduced please indicate the source: http://www.htmleaf.com/ziliaoku/... g/201506142036.html


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.