svg tutorial

Examples

<html>
<body>
<h1>My first SVG</h1>
<svg style="border: 1px solid; margin-left: 20px;">
    <circle r="20" stroke-width="2" fill="red" cx="100" cy="50" />
</svg>
</body>
</html>

  • (Cx, cy): center coordinates

  • stroke and stroke-width: how to draw the outline control

In HTML, embed, object

Use the embed tag

<embed src="circle1.svg" type="image/svg+xml" />

Using an object tag

<object data="circle1.svg" type="image/svg+xml"></object>

Use iframe tag

<iframe src="circle1.svg"></iframe>

Directly embedded svg tag

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
   <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" />
</svg>

rectangle

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <rect width="300" height="100"
          style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0);fill-opacity:0.1;"/>
</svg>

style / attribute

  • fill fill color
  • strok-width profile width
  • stroke outline color
  • fill-opacity: opacity of the fill color
  • stroke-opacity: Opacity outline color
  • opacity: Opacity of the whole element

  • width
  • height
  • rx, ry: generating fillets
  • x, y: coordinates of the origin, offset

Round

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <circle cx="100" cy="50" r="40" stroke="black"
  stroke-width="2" fill="red"/>
</svg>

style / attribute

  • cx, cy: center
  • r: Radius

oval

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="width:500px">
  <ellipse cx="300" cy="80" rx="100" ry="50"
  style="fill:yellow;stroke:purple;stroke-width:2"/>
</svg>

style / attribute

  • cx, cy: ellipse center
  • rx, ry: Radius

straight line

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <line x1="0" y1="0" x2="200" y2="200"
          style="stroke:rgb(255,0,0);stroke-width:2"/>
</svg>

Polygon

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <polygon points="200,10 250,190 160,210"
             style="fill:lime;stroke:purple;stroke-width:1"/>
</svg>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <polygon points="100,10 40,180 190,60 10,60 160,180"
             style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;" />
</svg>

  • fill-rule:nonzero:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="height: 200px">
    <polygon points="100,10 40,180 190,60 10,60 160,180"
             style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>

Broken line

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="200px">
    <polyline points="20,20 40,25 60,40 80,120 120,140 200,180"
              style="fill:none;stroke:black;stroke-width:3" />
</svg>

Path - path

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
    <path d="M150 0 L75 200 L225 200 Z" />
</svg>

  • M = moveto
  • L = lineto
  • H = horizontal lineto
  • V = vertical lineto
  • C = curveto
  • S = smooth curveto
  • Q = quadratic Bézier curve Bezier curve
  • T = smooth quadratic Bézier curveto
  • A = elliptical Arc
  • Z = closepath

Guess you like

Origin www.cnblogs.com/zhuxiang1633/p/11542321.html
SVG