canvas繪製貝濟埃曲線程式碼例項
分享一段程式碼例項,它利用canvas實現了繪製貝濟埃曲線的功能。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> button { display: block; margin: 0 0 10px 0; } </style> </head> <body> <button id="bezier" class="btn-bezier" type="button">貝濟埃曲線</button> <canvas id="canvas-bezier" class="can-beier" width="300" height="300"></canvas> <canvas id="canvas-quardratic" class="quardratic" width="300" height="300"></canvas> <script> var bezier = document.getElementById("bezier"); bezier.addEventListener("click", drawbezier, false); function drawbezier() { var canvasBezier = document.getElementById("canvas-bezier"); // canvasBezier.style.display = "block"; if (canvasBezier == null) { return false; } var context = canvasBezier.getContext("2d"); context.fillStyle = "#eeeeff"; context.fillRect(0, 0, 300, 300); var n = 0; var dx = 150; var dy = 150; var s = 100; context.beginPath(); context.globalCompositeOperation = 'and'; context.fillStyle = 'rgb(100,255,100)'; var x = Math.sin(0); var y = Math.cos(0); var dig = Math.PI / 15 * 11; context.moveTo(dx, dy); for (var i = 0; i < 30; i++) { var x = Math.sin(i * dig); var y = Math.cos(i * dig); context.bezierCurveTo(dx + x * s, dy + y * s - 100, dx + x * s + 100, dy + y * s, dx + x * s, dy + y * s); } context.closePath(); context.fill(); context.stroke(); } </script> </body> </html>
相關文章
- canvas繪製拋物線程式碼例項Canvas線程
- canvas實現的賽貝爾曲線效果程式碼例項Canvas
- canvas繪製扇形程式碼例項Canvas
- canvas繪製星星程式碼例項Canvas
- canvas 繪製雞蛋程式碼例項Canvas
- html5中canvas繪製貝塞爾曲線HTMLCanvas
- canvas繪製網格程式碼例項Canvas
- canvas繪製笑臉程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- 用canvas繪製一個曲線動畫——深入理解貝塞爾曲線Canvas動畫
- html5中canvas貝塞爾曲線繪製菊花HTMLCanvas
- js控制貝塞爾曲線程式碼例項JS線程
- canvas繪製米字旗程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製圓角矩形程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas
- canvas繪製熊貓頭像程式碼例項Canvas
- canvas繪製sin正弦曲線Canvas
- canvas繪製魚吃豆效果程式碼例項Canvas
- canvas繪製雪花飄落效果程式碼例項Canvas
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas繪製實心圓形程式碼例項Canvas
- canvas繪製網狀圓圈程式碼例項Canvas
- canvas繪製機器貓頭像程式碼例項Canvas
- canvas繪製矩形並填充顏色程式碼例項Canvas
- canvas繪製憤怒小鳥形象程式碼例項Canvas
- HTML5利用canvas繪製矩形程式碼例項HTMLCanvas
- canvas繪製五角星程式碼例項Canvas
- js按住滑鼠繪製線條程式碼例項JS
- canvas繪製帶有刻度的座標系程式碼例項Canvas
- webGL入門-四階貝塞爾曲線繪製Web
- css繪製圓形程式碼例項CSS
- svg繪製半圓程式碼例項SVG
- canvas線性漸變程式碼例項Canvas
- canvas螞蟻線效果程式碼例項Canvas