SVG basics | draw SVG straight lines, line lines, and polygon-

Source: Internet
Author: User
Tags polyline
This article describes the basic knowledge of html5svg. This article describes how to draw SVG straight lines, line and polygon, and some related knowledge .,. SVG basics | draw SVG straight lines, line lines, and polygon

SVG straight line

SVG An element is used to draw a line. The following is an example of creating a straight line.

   
    
    
    
  
 

The returned results of the code above are as follows:

The x1 and y1 attributes are used to specify the start point of a straight line, and the x2 and y2 attributes are used to specify the end point of a straight line. You can use the style attribute to set the color and stroke width for the line.

SVG line

The element is used to draw an SVG line. A broken line is a line connecting multiple connections. See the following example:

   
  
 

The returned results of the code above are as follows:

A line is defined by multiple points. Each vertex has the x and y attributes. The preceding example contains three vertices, which constitute a triangle. These three points are connected in a straight line and filled. The default fill color is black. The following example uses the fill color for filling.

     
  
 

You will find that only two sides of the triangle are filled with the stroke color, because only the lines between two points are drawn using the stroke color. No point in the above Code points to the starting point. If you need to draw all three edges, you also need a point to the starting position.

   
  
 

Like SVG straight lines, you can use the style attribute to set the color and stroke width for the line.

SVG Polygon

Element is used to draw SVG polygon. A polygon is a ry with three or more edges. Let's look at the following example of an SVG triangle:

   
   
 

Use Element. Although there are only three vertices, you will find that all three edges are drawn. This is because The element draws all straight lines between points, including the line from the last point to the first point. This is Element and code> The unique difference between elements.

We can plot the ry of more edges. Below is an example of an octagonal structure:

   
  
 

The above is the basis of SVG | the content of drawing SVG straight lines, broken lines, and polygon. For more information, see PHP Chinese Network (www.php1.cn )!

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.