DDR爱好者之家 Design By 杰米
效果图:
代码如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <canvas id="canvas"></canvas> <script> var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), canvasW = canvas.width = window.innerWidth, canvasH = canvas.height = window.innerHeight, canvasWHalf = canvasW / 2, canvasHHalf = canvasH / 2, xoff = canvasWHalf - 306, yoff = 50, bg = '00061a', id = 0, raindrops = [], minSize = 1, maxSize = 4, minSpeed = 5, maxSpeed = 20, minHue = 0, maxHue = 360, maxAmount = 50; function random(min, max) { if (arguments.length < 2) { max = min; min = 0; } return Math.floor(Math.random() * (max - min) + min); } function hexToRGB(hex, opacity) { var rgb = ''; hex.match(/.{2}/g).forEach(function(n) { rgb += (parseInt(n, 16)) + ','; }); return 'rgba(' + rgb + opacity + ')'; } function draw() { // Heart ctx.fillStyle = hexToRGB(bg, '0.1'); ctx.beginPath(); // Left half ctx.moveTo(0, 0); ctx.lineTo(canvasWHalf, 0); ctx.lineTo(304 + xoff, 97 + yoff); ctx.bezierCurveTo(282 + xoff, -5 + yoff, 80 + xoff, -6 + yoff, 76 + xoff, 165 + yoff); ctx.bezierCurveTo(74 + xoff, 251 + yoff, 184 + xoff, 300 + yoff, 304 + xoff, 447 + yoff); ctx.lineTo(canvasWHalf, canvasH); ctx.lineTo(0, canvasH); // Right half ctx.moveTo(canvasW, 0); ctx.lineTo(canvasWHalf, 0); ctx.lineTo(304 + xoff, 97 + yoff); ctx.bezierCurveTo(326 + xoff, 5 + yoff, 528 + xoff, 6 + yoff, 532 + xoff, 165 + yoff); ctx.bezierCurveTo(534 + xoff, 251 + yoff, 424 + xoff, 300 + yoff, 304 + xoff, 447 + yoff); ctx.lineTo(canvasWHalf, canvasH); ctx.lineTo(canvasW, canvasH); ctx.closePath(); ctx.fill(); // Raindrops for (var i = 1; i < id; i++) { raindrops[i].fall(); }; } var Raindrop = function() { id++; this.y = random(-canvasH); this.x = random(canvasW); this.size = random(minSize, maxSize); this.speed = random(minSpeed, maxSpeed); this.color = 'hsl(' + random(minHue, maxHue) + ',100%,55%)'; this.origColor = this.color; this.id = id; raindrops[id] = this; }; Raindrop.prototype.fall = function() { this.y += this.speed; if (this.y >= canvasH) { this.y = random(-canvasH); this.x = random(canvasW); } ctx.save(); ctx.beginPath(); var gradient = ctx.createRadialGradient(this.x, this.y, 0, this.x, this.y, this.size); gradient.addColorStop(0, '#fff'); gradient.addColorStop(0.5, this.color); gradient.addColorStop(1, hexToRGB(bg, 0)); ctx.rect(this.x, this.y, this.size, maxSpeed); ctx.fillStyle = gradient; ctx.fill(); ctx.closePath(); ctx.restore(); }; (function init() { ctx.fillStyle = '#' + bg; ctx.fillRect(0, 0, canvasW, canvasH); for (var i = 0; i < maxAmount; i++) { new Raindrop(); } }()); function animate() { draw(); window.requestAnimationFrame(animate); } window.requestAnimationFrame(animate); function mouseTrail(x, y) { ctx.save(); ctx.globalCompositeOperation = 'overlay'; ctx.fillStyle = 'rgba(255,255,255,0.1)'; ctx.arc(x, y, 50, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } window.addEventListener('mousemove', function(cursor) { mouseTrail(cursor.x, cursor.y); }); </script> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]