canvas怎么實(shí)現(xiàn)愛(ài)心和彩虹雨的效果

小編給大家分享一下canvas怎么實(shí)現(xiàn)愛(ài)心和彩虹雨的效果,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

10年積累的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有北關(guān)免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

代碼如下:

<!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>

以上是canvas怎么實(shí)現(xiàn)愛(ài)心和彩虹雨的效果的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

新聞名稱:canvas怎么實(shí)現(xiàn)愛(ài)心和彩虹雨的效果
文章來(lái)源:http://m.kartarina.com/article22/pipjcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站網(wǎng)站營(yíng)銷網(wǎng)站維護(hù)品牌網(wǎng)站制作云服務(wù)器ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)
主站蜘蛛池模板: 中文字幕乱妇无码AV在线| 亚洲AV无码乱码国产麻豆| 中文字幕av无码一二三区电影| 亚洲AV无码AV日韩AV网站| 亚洲成A∨人片天堂网无码| 亚洲国产精品无码久久久秋霞2 | 夜夜精品无码一区二区三区| 国产综合无码一区二区辣椒 | 99久无码中文字幕一本久道| 十八禁视频在线观看免费无码无遮挡骂过 | 国产成人无码免费看片软件| 中文字幕丰满乱子无码视频| 亚洲看片无码在线视频| 国产自无码视频在线观看| 亚洲精品无码专区在线| 久久久无码精品亚洲日韩蜜臀浪潮| 高潮潮喷奶水飞溅视频无码| 亚洲精品久久无码| 无码人妻精品一区二区在线视频| AA区一区二区三无码精片| 久久久亚洲精品无码| 国模吧无码一区二区三区| 国产精品爆乳奶水无码视频 | 人妻丰满熟妇无码区免费| 国产精品爽爽va在线观看无码| 台湾无码一区二区| 中文字幕丰满乱子无码视频| 天码av无码一区二区三区四区| 精品少妇人妻av无码久久| 亚洲爆乳精品无码一区二区三区| 久久久久亚洲av无码专区导航| 亚洲免费日韩无码系列| 免费无码一区二区三区蜜桃大| 无码欧精品亚洲日韩一区| 国产亚洲AV无码AV男人的天堂| 国模无码视频一区二区三区| 亚洲日韩精品A∨片无码加勒比 | 亚洲AV无码专区亚洲AV伊甸园| 精品久久久无码人妻字幂| 人妻丰满熟妇AV无码区| 精品久久久久久无码人妻中文字幕|