利用html5 canvas 畫圖的一個例子
下面給一個利用html5 canvas 畫圖的一個例子的原始碼:
<!DOCTYPE <!DOCTYPE html>
<html>
<head>
<title>Test Canvas</title>
</head>
<body>
<canvas id ="myCanvas" width="400" height="400" style="border:1px solid #d3d3d3">Your browser does not support the HTML5 canvas tag</canvas>
<script type="text/javascript">
var jsonObj = [{"p":"066089067089067090068090072093077100079104080108082114084122085130087143088149089162090170090178090179090180"},{"p":"083100083100084100084100085098090096102091107088112086117084124083133082136083141084146091147093148097148102147117144130143135140147138156137161136165136167135169135170"},{"p":"086131086131088131095129107126112124114123120121122120124120127119129119131118132119"},{"p":"098172098172103170114166123163127162130161134160135159136158"},{"p":"115058115058115062114074113081113085113096113104113108113118113132114145114157114169116186115198115204114211114217113218113219113219"},{"p":"157062157062158062160062164062180060184058191057194056198056204055207054210054212055212056210058198070189079184082180086174091172094168096162102160103158105158106158106158106160106168106179105186104196103203103207103215105219106224110226116227122228132227144224155220167217178216181213189210194206204205206203208202210199212196213195212189209180198177194"},{"p":"173117173118172118170122166131165133163137160141158144155148149156147159144165142168142168"},{"p":"207120207120206122205127200138197142188152184157180161174168169173163180158184148194140201137204136204134205134206"},{"p":"066089067089067090068090072093077100079104080108082114084122085130087143088149089162090170090178090179090180"},{"p":"083100083100084100084100085098090096102091107088112086117084124083133082136083141084146091147093148097148102147117144130143135140147138156137161136165136167135169135170"},{"p":"086131086131088131095129107126112124114123120121122120124120127119129119131118132119"},{"p":"098172098172103170114166123163127162130161134160135159136158"},{"p":"115058115058115062114074113081113085113096113104113108113118113132114145114157114169116186115198115204114211114217113218113219113219"},{"p":"157062157062158062160062164062180060184058191057194056198056204055207054210054212055212056210058198070189079184082180086174091172094168096162102160103158105158106158106158106160106168106179105186104196103203103207103215105219106224110226116227122228132227144224155220167217178216181213189210194206204205206203208202210199212196213195212189209180198177194"},{"p":"173117173118172118170122166131165133163137160141158144155148149156147159144165142168142168"},{"p":"207120207120206122205127200138197142188152184157180161174168169173163180158184148194140201137204136204134205134206"}];
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "red";
for (var i = 0; i < jsonObj.length; i++) {
var strokePointStr = jsonObj[i];
ctx.beginPath();
var firstX = strokePointStr.p.substr(0, 3);
var firstY = strokePointStr.p.substr(3, 3);
ctx.moveTo(firstX , firstY);
var count = (strokePointStr.p.length) / (3 * 2);
for (var j = 0; j <count; j++) {
firstX = strokePointStr.p.substr(j * 3 * 2, 3);
firstY = strokePointStr.p.substr(j * 3 * 2 + 3, 3);
ctx.lineTo(firstX, firstY);
};
ctx.stroke();
};
</script>
</body>
</html>
大家跑上面的例子,畫出的是什麼圖形?
相關文章
- HTML5利用canvas,把多張圖合併成一張圖片HTMLCanvas
- 16個非常有趣的HTML5 Canvas動畫特效集合HTMLCanvas動畫特效
- 用HTML5的canvas畫太陽系HTMLCanvas
- 基於 Canvas 的 HTML5 文字動畫特效CanvasHTML動畫特效
- 使用canvas畫出一個矩形Canvas
- canvas畫圖採坑Canvas
- 用canvas畫一個進度盤Canvas
- 用canvas畫一個七竅板Canvas
- 用 Canvas + WASM 畫一個迷宮CanvasASM
- 請使用canvas畫一個橢圓Canvas
- 基於 HTML5 Canvas 實現的文字動畫特效HTMLCanvas動畫特效
- Html5 Canvas動畫基礎(碰撞檢測)HTMLCanvas動畫
- html5中canvas元素建立畫布介紹HTMLCanvas
- 超酷!!HTML5 Canvas 水流樣式 Loading 動畫HTMLCanvas動畫
- Canvas畫圖-一個比想象中更騷氣的圓(漸變圓環)Canvas
- 用canvas實現一個簡單的畫板Canvas
- 基於 HTML5 Canvas 實現文字動畫特效HTMLCanvas動畫特效
- HTML5 Canvas 超逼真煙花綻放動畫HTMLCanvas動畫
- 如何抓取canvas畫布中的圖片Canvas
- 用 canvas 做一個 DVD 待機動畫Canvas動畫
- 又雙叒叕是一個 canvas 動畫Canvas動畫
- 利用 canvas 實現圖片壓縮Canvas
- 畫影圖形: SVG & Canvas 圖形對比SVGCanvas
- 一個好用的畫圖工具 excalidraw
- Canvas+Socket搞出一個多人遊玩的“我畫你猜”Canvas
- vue3+ts實現一個canvas畫筆繪圖功能,並匯出相關的切片VueCanvas繪圖
- HTML5 Canvas(實戰:繪製餅圖2 Tooltip)HTMLCanvas
- expdp一個例子
- ## H5 canvas畫圖白板踩坑H5Canvas
- 基於 Canvas 的 HTML5 互動式地鐵線路圖CanvasHTML
- 基於 HTML5 Canvas 的 3D 熱力雲圖效果HTMLCanvas3D
- HTML5的SVG和Canvas的使用HTMLSVGCanvas
- HTML5 Canvas 詳解HTMLCanvas
- HTML5(五)——Canvas APIHTMLCanvasAPI
- 從MDN上的canvas例子受到的啟發Canvas
- Flutter | 通過一個小例子帶你認識動畫 AnimationFlutter動畫
- 手把手教你實現一個canvas智繪畫板Canvas
- 快速建立 HTML5 Canvas 電信網路拓撲圖HTMLCanvas
- 可擴充套件物件導向的canvas畫圖程式套件物件Canvas