清華大佬耗費三個月吐血整理的幾百G的資源,免費分享!....>>>
SVG <path>
SVG 路徑 - <path>
<path> 元素用于定義一個路徑。
下面的命令可用于路徑數(shù)據(jù):
- M = moveto
- L = lineto
- H = horizontal lineto
- V = vertical lineto
- C = curveto
- S = smooth curveto
- Q = quadratic Bézier curve
- T = smooth quadratic Bézier curveto
- A = elliptical Arc
- Z = closepath
注意:以上所有命令均允許小寫字母。大寫表示絕對定位,小寫表示相對定位。
實例 1
上面的例子定義了一條路徑,它開始于位置150 0,到達位置75 200,然后從那里開始到225 200,最后在150 0關(guān)閉路徑。
下面是SVG代碼:
實例
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"><path d="M150 0 L75 200 L225 200 Z" />
</svg>
嘗試一下 »
對于Opera用戶:查看SVG文件(右鍵單擊SVG圖形預覽源)。
實例 2
使用貝茲曲線流暢的曲線模型,可無限期的縮放。一般情況下,用戶選擇兩個端點和一個或兩個控制點。一個一個控制點的貝塞爾曲線被稱為二次貝塞爾曲線和兩個控制點的那種被稱為立方體。
下面的例子創(chuàng)建了一個二次貝塞爾曲線,A和C分別是起點和終點,B是控制點:
下面是SVG代碼:
實例
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"><path id="lineAB" d="M 100 350 l 150 -300" stroke="red"
stroke-width="3" fill="none" />
<path id="lineBC" d="M 250 50 l 150 300" stroke="red"
stroke-width="3" fill="none" />
<path d="M 175 200 l 150 0" stroke="green" stroke-width="3"
fill="none" />
<path d="M 100 350 q 150 -300 300 0" stroke="blue"
stroke-width="5" fill="none" />
<!-- Mark relevant points -->
<g stroke="black" stroke-width="3" fill="black">
<circle id="pointA" cx="100" cy="350" r="3" />
<circle id="pointB" cx="250" cy="50" r="3" />
<circle id="pointC" cx="400" cy="350" r="3" />
</g>
<!-- Label the points -->
<g font-size="30" font="sans-serif" fill="black" stroke="none"
text-anchor="middle">
<text x="100" y="350" dx="-30">A</text>
<text x="250" y="50" dy="-10">B</text>
<text x="400" y="350" dx="30">C</text>
</g>
</svg>
嘗試一下 »
對于Opera用戶:查看SVG文件(右鍵單擊SVG圖形預覽源)。
復雜嗎?是的!!由于在繪制路徑時的復雜性,強烈建議使用SVG編輯器來創(chuàng)建復雜的圖形。
掃碼二維碼 獲取免費視頻學習資料