canvas繪製網格程式碼例項
分享一段程式碼例項,它實現了利用canvas繪製網格的功能。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> </head> <body> <canvas id="canvas" width="500" height="500"></canvas> <script> var canvas = document.getElementById("canvas"), context = canvas.getContext('2d'); //function function drawGrid(context, color, stepx, stepy) { context.strokeStyle = color; context.lineWidth = 0.5; for (var i = stepx + 0.5; i < context.canvas.width; i += stepx) { context.beginPath(); context.moveTo(i, 0); context.lineTo(i, context.canvas.height); context.stroke(); } for (var i = stepy + 0.5; i < context.canvas.height; i += stepy) { context.beginPath(); context.moveTo(0, i); context.lineTo(context.canvas.width, i); context.stroke(); } } //Initialization drawGrid(context, 'lightgray', 10, 10); </script> </body> </html>
相關文章
- canvas繪製扇形程式碼例項Canvas
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製拋物線程式碼例項Canvas線程
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製圓形鐘錶程式碼例項Canvas
- css繪製圓形程式碼例項CSS
- canvas繪製網格射線效果Canvas
- SVG拖動繪製矩形程式碼例項SVG
- canvas刮刮樂程式碼例項Canvas
- canvas載入效果程式碼例項Canvas
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- CSS3繪製太極圖程式碼例項詳解CSSS3
- canvas translate()、scale()和rotate()方法程式碼例項Canvas
- UML類圖繪製例項
- 例項QT程式 —— Qt自繪製小時鐘QT
- 使用canvas繪製dribble風格水波浪Canvas
- E-R圖繪製例項
- 資料流圖繪製例項
- Python例項:僅繪製圖例而不繪製實際的圖形Python
- canvas 繪製扇形Canvas
- canvas 繪製文字Canvas
- canvas 繪製矩形Canvas
- 小程式canvas居中剪裁繪製圖片Canvas
- canvas 繪製線條Canvas
- canvas 繪製圓形Canvas
- canvas繪製流星效果Canvas
- canvas繪製直線Canvas
- canvas lineWidth 繪製原理Canvas
- canvas lineWidth繪製原理Canvas
- 原生Canvas繪製餅圖,我是不是被騙程式碼了Canvas
- 瞭解下Foundation 網格例項
- QT OPENGL 與 shader 繪製展示視訊程式碼例項 OPenGL直接顯示YUV資料QT
- Canvas 繪製雷達圖Canvas
- canvas 繪製圓角矩形Canvas
- canvas 繪製雙線技巧Canvas
- canvas繪製矩形框Canvas
- canvas繪製風車效果Canvas