canvas蔚藍星空效果
分享一段程式碼例項,它利用canvas實現了蔚藍星空效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; } #starrynight { background: -webkit-linear-gradient(#00111e 30%, #033d5e); background: -moz-linear-gradient(#00111e 30%, #033d5e); background: -o-linear-gradient(#00111e 30%, #033d5e); background: linear-gradient(#00111e 30%, #033d5e); overflow: hidden; } </style> </head> <body> <canvas id="starrynight"></canvas> <script> function drawing() { var c = document.getElementById('starrynight'); var ctx = c.getContext('2d'); var xMax = c.width = window.screen.availWidth; var yMax = c.height = window.screen.availHeight; var hmTimes = Math.round(xMax + yMax); for (var i = 0; i <= hmTimes; i++) { var randomX = Math.floor((Math.random() * xMax) + 1); var randomY = Math.floor((Math.random() * yMax) + 1); var randomSize = Math.floor((Math.random() * 2) + 1); var randomOpacityOne = Math.floor((Math.random() * 9) + 1); var randomOpacityTwo = Math.floor((Math.random() * 9) + 1); var randomHue = Math.floor((Math.random() * 360) + 1); if (randomSize > 1) { ctx.shadowBlur = Math.floor((Math.random() * 15) + 5); ctx.shadowColor = "white"; } ctx.fillStyle = "hsla(" + randomHue + ", 30%, 80%, ." + randomOpacityOne + randomOpacityTwo + ")"; ctx.fillRect(randomX, randomY, randomSize, randomSize); } } drawing(); </script> </body> </html>
相關文章
- canvas繪製經典星空連線效果Canvas
- canvas流星劃過星空效果程式碼例項Canvas
- canvas動畫特效 之 星空Canvas動畫特效
- css3星空效果程式碼例項CSSS3
- 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
- canvas水平勻速運動效果Canvas
- canvas環形進度條效果Canvas
- canvas具有漸變效果的矩形Canvas
- canvas實現 漂亮的下雨效果Canvas
- canvas漫天飛雪效果程式碼Canvas
- 簡單的 canvas 翻角效果Canvas
- canvas圓形隨機漂浮效果Canvas隨機
- canvas火焰效果程式碼例項Canvas
- canvas小畫板——(3)筆鋒效果Canvas
- 由canvas實現btn效果有感Canvas
- canvas繪製卡通人臉形象效果Canvas
- Canvas + JavaScript 製作圖片粒子效果CanvasJavaScript
- canvas字母雨效果程式碼例項Canvas
- canvas繪製多個圓圈效果Canvas
- canvas繪製網格射線效果Canvas