SVG(Scalable Vector Graphics):可缩放矢量图形
SVG规范 https://www.w3.org/Graphics/SVG/
基本形状
线段
1 | <line x1="75" y1="95" x2="135" y2="85" style="stroke: black;"/> |
x1, y1起点坐标x2, y2终点坐标stylestroke-width笔画宽度stroke笔画颜色stroke-opacity不透明度(0.0-1.0,0表示完全透明,1表示完全不透明)stroke-dasharray线的长度和空隙的长度,实现点线或虚线
矩形
1 | <rect x="10" y="10" width="30" height="30"/> |
x, y矩形左上角坐标width, height矩形宽和高rx, ryx,y方向圆角半径,最大值为矩形宽度,高度的一半,如果只指定其中一个值,则认为他们相等rx, ry不相等意味着什么:圆角是椭圆而不是圆的一部分
圆
1 | <circle cx="70" cy="95" r="50"/> |
cx, cy圆心坐标r半径
椭圆
1 | <ellipse cx="75" cy="75" rx="20" ry="5"/> |
cx, cy中心坐标rx, ryx,y方向半径
多边形
1 | <polygon points="0,0 0,100 100,100 100,0" style="fill: none; stroke: black;"/> |
points 各点x,y坐标对,多边形为封闭图形,会自动回到起始坐标
折线
1 | <polyline points="0,0 0,100 100,100 100,0" style="fill: none; stroke: black;"/> |
同多边形,图形不封闭
路径
1 | <path d="M10,20 L100,20 L100,50"/> |
ddata,描述路径的命令Mx,ymoveto,每个路径都必须以 moveto 命令开始,设置当前位置Lx,ylineto,绘制一条线lx,y等价于Lcurrent_x+x,current_y+yZclosepath,回到起点Hx水平线,等价于Lx,current_yhx水平线,等价于lx,0Vy垂直线,等价于Lcurrent_x,yvy垂直线,等价于l0,y
文本
1 | <text x="20" y="30" style="font-family: monospace; |
分组和引用对象
<g>
1 | <g id="box" style="stroke: black; fill: none;"> |
用于组合元素
<use>
1 | <use href="#box" x="40" y="0"/> |
href引用元素x, y移动到的位置
<defs>
1 | <defs> |
只定义,不显示
坐标变换
translate
translate(x, y) 移动
scale
scale(xFactor, yFactor) 缩放
scale(x) 等价于 scale(x, x)
rotate
rotate(angle) 以原点(0, 0) 为中心旋转
rotate(angle, x, y) 以(x, y) 为中心旋转
组合
1 | <defs><text id="hello" style="font-size: 12px;">Hello World!</text></defs> |
平移后缩放
渐变
线性渐变
1 | <defs> |
linearGradient 线性渐变
stop 渐变点
径向渐变
1 | <defs> |
radialGradient 径向渐变