DEMO: http://sources.ikeepstudying.com/svg/class/class2.php SVG <rect> SVG Shapes SVG有一些预定义的形状元素,可被开发者使用和操作: 矩形 <rect> 圆形…
July 8, 2015
SVG 教程 (三)圆形,椭圆,直线
DEMO: http://sources.ikeepstudying.com/svg/class/class3.php
SVG <circle>
SVG 圆形 – <circle>
<circle> 标签可用来创建一个圆:
下面是SVG代码:
<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>
对于Opera用户:查看SVG文件(右键单击SVG图形预览源)。
代码解析:
- cx和cy属性定义圆点的x和y坐标。如果省略cx和cy,圆的中心会被设置为(0, 0)
- r属性定义圆的半径
SVG <ellipse>
SVG 椭圆 – <ellipse>
实例 1
<ellipse> 元素是用来创建一个椭圆:
椭圆与圆很相似。不同之处在于椭圆有不同的x和y半径,而圆的x和y半径是相同的:
下面是SVG代码:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="300" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2"/> </svg>
对于Opera用户:查看SVG文件(右键单击SVG图形预览源)。
代码解析:
- CX属性定义的椭圆中心的x坐标
- CY属性定义的椭圆中心的y坐标
- RX属性定义的水平半径
- RY属性定义的垂直半径
实例 2
下面的例子创建了三个累叠而上的椭圆:
下面是SVG代码:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="240" cy="100" rx="220" ry="30" style="fill:purple"/> <ellipse cx="220" cy="70" rx="190" ry="20" style="fill:lime"/> <ellipse cx="210" cy="45" rx="170" ry="15" style="fill:yellow"/> </svg>
对于Opera用户:查看SVG文件(右键单击SVG图形预览源)。
实例 3
下面的例子组合了两个椭圆(一个黄的和一个白的):
下面是SVG代码:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"> <ellipse cx="240" cy="50" rx="220" ry="30" style="fill:yellow"/> <ellipse cx="220" cy="50" rx="190" ry="20" style="fill:white"/> </svg>
对于Opera用户:查看SVG文件(右键单击SVG图形预览源)。
SVG <line>
SVG 直线 – <line>
<line> 元素是用来创建一个直线:
下面是SVG代码:
<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>
对于Opera用户:查看SVG文件右键单击SVG图形预览源)。
- x1 属性在 x 轴定义线条的开始
- y1 属性在 y 轴定义线条的开始
- x2 属性在 x 轴定义线条的结束
- y2 属性在 y 轴定义线条的结束
转自: http://www.runoob.com/svg/svg-line.html
更多参考:
SVG 入门教程系列(列表):
2 Comments