天天看點

SVG <polygon>

<polygon> 标簽用來建立含有不少于三個邊的圖形。

多邊形是由直線組成,其形狀是"封閉"的(所有的線條

連接配接起來)。

SVG <polygon>

polygon來自希臘。 "Poly"

意味 "many" , "gon" 意味 "angle".

下面是SVG代碼:

<svg height="210" width="500">

<polygon points="200,10 250,190 160,210"

style="fill:lime;stroke:purple;stroke-width:1"/>

</svg>

對于Opera使用者: 檢視SVG檔案(右鍵單擊SVG圖形預覽源)。

<b>代碼解析:</b>

points 屬性定義多邊形每個角的 x 和 y 坐标

下面的示例建立一個四邊的多邊形:

&lt;svg height="250" width="500"&gt;

&lt;polygon points="220,10 300,210 170,250 123,234" style="fill:lime;stroke:purple;stroke-width:1" /&gt;

使用 &lt;polygon&gt; 元素建立一個星型:

&lt;svg height="210" width="500"&gt;

&lt;polygon points="100,10 40,198 190,78 10,78 160,198"

style="fill:lime;stroke:purple;stroke-width:5;fill-rule:nonzero;" /&gt;

改變 fill-rule 屬性為 "evenodd":

style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" /&gt;