canvas繪製網格射線效果
分享一段程式碼例項,它實現了利用canvas繪製網格射線的功能。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> body { background: #000; overflow: hidden; margin: 0; padding: 0; } canvas { width: 45%; margin: 5% 30%; } </style> </head> <body> <canvas id="canv" width="600" height="600"></canvas> <script type="text/javascript"> var c; var $; var w = 600; var h = 600; constant = 15; var rad = 300; var timeout = 0; c = document.getElementById("canv"); $ = c.getContext("2d"); drawLines(); function drawLines() { $.fillRect(0, 0, w, h); $.translate(w / 2, h / 2); for (var i = 0; i < 25; i++) { for (var n = -45; n <= 45; n += constant) { setTimeout("draw(" + n + ");", 100 * timeout); timeout++; } } } function draw(n) { $.beginPath(); $.moveTo(0, rad); var radians = Math.PI / 180 * n; var x = (rad * Math.sin(radians)) / Math.sin(Math.PI / 2 - radians); $.lineTo(x, 0); if (Math.abs(n) == 45) { $.strokeStyle = rndColor(); $.lineWidth = 2; } else if (n == 0) { $.strokeStyle = "rgb(200,200,200)"; $.lineWidth = .5; } else { $.strokeStyle = "rgb(110,110,110)"; $.lineWidth = .5; } $.stroke(); $.rotate((Math.PI / 180) * 15); } function rndColor() { var r = 255 * Math.random() | 0, g = 255 * Math.random() | 0, b = 255 * Math.random() | 0; return 'rgb(' + r + ',' + g + ',' + b + ')'; } </script> </body> </html>
相關文章
- canvas繪製經典星空連線效果Canvas
- canvas繪製流星效果Canvas
- canvas繪製網格程式碼例項Canvas
- canvas繪製風車效果Canvas
- canvas繪製帶有漸變效果的直線Canvas
- canvas 繪製線條Canvas
- canvas繪製直線Canvas
- canvas 繪製雙線技巧Canvas
- canvas繪製卡通人臉形象效果Canvas
- canvas繪製多個圓圈效果Canvas
- jQuery繪製網格效果程式碼例項jQuery
- canvas繪製sin正弦曲線Canvas
- canvas繪製太陽系運動效果Canvas
- canvas繪製北斗七星效果Canvas
- canvas繪製圓環效果程式碼例項Canvas
- canvas繪製圓盤走動鐘錶效果Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas
- 使用 HTML5 Canvas 繪製的水滴效果HTMLCanvas
- 使用canvas繪製dribble風格水波浪Canvas
- canvas核心技術-如何繪製線段Canvas
- html5中canvas繪製線段HTMLCanvas
- canvas繪製圓形框效果不填充內部Canvas
- canvas繪製魚吃豆效果程式碼例項Canvas
- canvas繪製雪花飄落效果程式碼例項Canvas
- canvas 繪製矩形Canvas
- canvas 繪製扇形Canvas
- canvas 繪製文字Canvas
- canvas 奇巧淫技(二)繪製箭頭路徑效果Canvas
- canvas繪製旋轉一定角度的矩形效果Canvas
- canvas繪製拋物線程式碼例項Canvas線程
- html5中canvas線段繪製太陽花HTMLCanvas
- canvas 繪製圓形Canvas
- CSS & SVG 繪製寫作網格線的3種方式CSSSVG
- html5中canvas繪製貝塞爾曲線HTMLCanvas
- 利用canvas陰影功能與雙線技巧繪製軌道交通大屏專案效果Canvas