SVG图形编码

svg:能够不改变质量的状况下缩放

  1. svg必须有<svg></svg>包含
  2. 能够绘制不一样的形状矩形:rect,圆形:circle,椭圆:ellipse,线:line,折线:polyline,多边形:polygon,路径:path
  3. 绘制不一样的图形则应该使用不一样的标签标记如圆形则使用<svg>circle</svg>
  4. 能够将svg保存为svg格式
  5. x,y表示起始坐标
  6. fill:填充的颜色,stroke:画的颜色,stroke-width:画的宽度(通俗来说就是边框)
  7. 其实和css3的canvas差很少

矩形:rect

    

<svg>
  <rect fill="red" height="100" id="rect" stroke="gray" stroke-width="10" width="100" x="20" y="20"></rect>
</svg>

圆角矩形:设置rx,ry(圆心的坐标)的值便可

 

<svg>
  <circle id="circle"cx="100" cy="80" r="50" stroke="gray" stroke-width="10" fill="red">		
</svg>

圆形:circle

circle:没有x,y的属性由于已经设置好了圆心cx,cycss

  

<svg class="grid-50">
  <rect fill="red" height="100" id="rect" stroke="gray" stroke-width="10" width="100" x="20" y="20"></rect>
</svg>

椭圆:ellipse

ellipse:椭圆其实就是矩形而后边框是圆角html

 

<svg >
  <ellipse  rx=100 ry=30 cx=150 cy=60 fill="yellow" stroke="gray" />	
</svg>

线段:line(两点肯定一条直线)

    

<svg>
  <line x1="0" y1="0" x2="200" y2="20" fill="gray" stroke="gray" stroke-width="2" />
</svg>

折线:polyline(就是设置多个坐标点)

   

注意不能使用(0,0)是无效的node

<svg>
  <polyline points="0,0  0,20  20,20  20,40  40,40"  fill="white" stroke="gray" stroke-width="2" />
</svg>

多边形:polygon

  

固然更复杂的图形,只要知道各个点的坐标便可css3

<svg >
  <polygon points="50,50 0,100 100,100 50,50" fill="blue" stroke="gray" stroke-width="1">	  
</svg>

路径:path(上面全部的图形 均可以经过path来绘制)

下面的命令可用于路径数据:canvas

  • M = moveto  //坐标移动到
  • L = lineto  //画到
  • H = horizontal lineto 
  • V = vertical lineto
  • C = curveto
  • S = smooth curveto
  • Q = quadratic Belzier curve
  • T = smooth quadratic Belzier curveto
  • A = elliptical Arc  //椭圆
  • Z = closepath  //结束路径

注释:以上全部命令均容许小写字母。大写表示绝对定位,小写表示相对定位。app

必须按照规则书写svg

<svg>
  <path d="M50 50 L200 50 L200 0 L50 0 Z" fill="blue" stroke="gray" stroke-width="2" />	
</svg>
 
原文地址url: http://liteng.org/node/51
相关文章
相关标签/搜索