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="cvs" width="500" height="500"></canvas> <script> var cvs = document.getElementById('cvs'); var ctx = cvs.getContext('2d'); /* * 封裝一個畫等腰三角形的函式 * */ // 等腰三角形類 function SJX(x, y, w, h) { this.x = x; this.y = y; this.w = w; this.h = h; } // 給SJX類原型擴充一個繪製方法 SJX.prototype = { draw: function () { ctx.moveTo(this.x, this.y); ctx.lineTo(this.x + this.w / 2, this.y + this.h); ctx.lineTo(this.x - this.w / 2, this.y + this.h); ctx.lineTo(this.x, this.y); ctx.stroke(); } }; var sjx1 = new SJX(50, 50, 100, 50); var sjx2 = new SJX(200, 50, 50, 80); var sjx3 = new SJX(300, 50, 60, 60); sjx1.draw(); sjx2.draw(); sjx3.draw(); </script> </body> </html>
相關文章
- canvas 繪製矩形Canvas
- canvas 繪製扇形Canvas
- canvas 繪製文字Canvas
- canvas 繪製線條Canvas
- canvas 繪製圓形Canvas
- canvas繪製流星效果Canvas
- canvas繪製直線Canvas
- Canvas 繪製雷達圖Canvas
- canvas繪製動畫的技巧Canvas動畫
- canvas 繪製立體圓環Canvas
- canvas 繪製文字詳解Canvas
- canvas 繪製圓角矩形Canvas
- canvas 繪製矩形缺角Canvas
- canvas 繪製雙線技巧Canvas
- canvas繪製風車效果Canvas
- canvas繪製笑臉表情Canvas
- canvas繪製太陽系Canvas
- canvas繪製矩形框Canvas
- Canvas 繪製風向動畫Canvas動畫
- CSS繪製三角形CSS
- canvas 繪製圖案是重疊繪製而不是重置Canvas
- canvas繪製圖案是重疊繪製而不是重置Canvas
- Canvas(3)---繪製餅狀圖Canvas
- canvas系列教程之繪製矩形Canvas
- 用canvas繪製流星夜空Canvas
- 使用canvas繪製圓弧動畫Canvas動畫
- canvas繪製不重合的圓Canvas
- canvas繪製sin正弦曲線Canvas
- 純css繪製三角形CSS
- 流水賬系列之Canvas繪製-02Canvas
- canvas繪製扇形程式碼例項Canvas
- canvas lineWidth繪製原理Canvas
- canvas lineWidth 繪製原理Canvas
- canvas繪製卡通人臉形象效果Canvas
- canvas繪製圖片drawImage學習Canvas
- canvas繪製星星程式碼例項Canvas
- canvas繪製多個圓圈效果Canvas
- canvas繪製網格射線效果Canvas