雨中悄然 发表于 2023-2-17 22:26

鱼儿生日快乐


<style>
#papa { left: -214px; width: 1024px; height: 640px; background: gray url('https://pic.imgdb.cn/item/63ef8e35f144a010071bb983.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; position: relative; }
#canv { position: absolute; }
#disc { position: absolute; width: 40px; height: 40px; left: 10px; bottom: 10px; background: conic-gradient(red,orange,yellow,green,teal,blue,purple); mask: radial-gradient(transparent 4px,red 0); -webkit-mask: radial-gradient(transparent 4px,red 0); border-radius: 50%; cursor: pointer; animation: rot 2s linear infinite; }
#lrcbox { position: absolute; left: 60px; bottom: 10px;font: bold 22px / 40px sans-serif; color: #859670; text-shadow: 2px 2px 4px #222; }
@keyframes rot { to { transform: rotate(360deg); } }
</style>

<div id="papa">
      <span id="lrcbox">鱼儿 生日快乐</span>
      <canvas id="canv"></canvas>
      <span id="disc"></span>
</div>

<script>
(function() {
      let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
      let ctx = canv.getContext('2d');
      let w = canv.width = papa.offsetWidth, h = canv.height = papa.offsetHeight, particles = [], idx = 0, aud = new Audio();
      
      aud.src = 'https://music.163.com/song/media/outer/url?id=1433496995.mp3';
      aud.loop = true;
      aud.autoplay = true;
      
      disc.style.animationPlayState = aud.paused ? 'paused' : 'running';
      disc.onclick = () => aud.paused ? aud.play() : aud.pause();
      aud.addEventListener('playing',()=> disc.style.animationPlayState = 'running');
      aud.addEventListener('pause',()=> disc.style.animationPlayState = 'paused');

      canv.onclick = function(event) {
                let x = event.offsetX || event.layerX, y = event.offsetY || event.layerY;
                createParticle(x, y);
      }

      function createParticle(x, y) {
                let count = 100, radius = 10;
                for (let j = 0; j < count; j ++) {
                        let p = {};
                        let angle = 360 / count * j, radian = Math.PI / 180 * angle;
                        p.radius = radius;
                        p.startX = x;
                        p.startY = y;
                        p.radian = radian;
                        p.rgb = `${num(0,255)},${num(0,255)},${num(0,255)},`;
                        p.alpha = (Math.floor(Math.random() * 101)) / 100;
                        p.speed = (Math.random() * 5) + 0.4;
                        p.radius = p.speed;
                        particles.push(p);
                }
      }

      function drawParticle() {
                ctx.fillStyle = 'transparent';
                ctx.fillRect(0, 0, w, h);
                for (let j = 0; j < particles.length; j++) {
                        let p = particles;
                        let resultX = Math.cos(p.radian) * p.radius;
                        let resultY = Math.sin(p.radian) * p.radius + 0.4;
                        p.startX += resultX;
                        p.startY += resultY;
                        p.radius *= 1 - p.speed / 100;
                        p.alpha -= 0.005;
                        if (p.alpha <= 0) {
                              particles.splice(j, 1);
                              continue;
                        }
                        ctx.beginPath();
                        ctx.arc(p.startX, p.startY, 2, 0, 360, false);
                        ctx.closePath();
                        ctx.fillStyle = 'rgba(' + p.rgb + p.alpha + ')';
                        ctx.fill();
                }
      }

      function fade() {
                ctx.globalCompositeOperation = 'destination-out';
                ctx.fillStyle = 'rgba(0, 0, 0, .1)';
                ctx.fillRect(0, 0, w, h);
                ctx.globalCompositeOperation = 'lighter';
      }

      function render() {
                idx ++;
                fade();
                drawParticle();
                if(idx > 20) {
                        createParticle(Math.random() * w, Math.random() * h/2);
                        idx = 0;
                }
                requestAnimationFrame(render);
      }

      render();
})();
</script>

雨中悄然 发表于 2023-2-17 22:27

@鱼儿

鱼儿 发表于 2023-2-18 01:11

谢谢悄然{:6_240:}

庶民 发表于 2023-2-18 05:52

在此借这个帖子,也来祝福您,生日快乐,天天快乐。

梦油 发表于 2023-2-18 09:21

很高兴和雨中悄然一起祝福语鱼儿生日快乐。

海笑 发表于 2023-2-18 10:00

共祝鱼儿生日快乐!

红影 发表于 2023-2-18 10:08

悄然聪慧,弄了这么多鱼儿的头像,还有漂亮的烟花。这个又喜庆又漂亮。同祝鱼儿生日快乐{:4_199:}

小九 发表于 2023-2-18 11:06

很喜庆的帖子,同贺鱼儿生日快乐!{:5_166:}{:4_171:}

鱼儿 发表于 2023-2-18 21:47

谢谢大家!{:4_204:}

马黑黑 发表于 2023-2-19 12:11

{:4_187:}

雨中悄然 发表于 2023-2-19 12:47

马黑黑 发表于 2023-2-19 12:11


老师跑得好快{:4_173:}

雨中悄然 发表于 2023-2-19 12:47

鱼儿 发表于 2023-2-18 21:47
谢谢大家!

不客气的

雨中悄然 发表于 2023-2-19 12:48

小九 发表于 2023-2-18 11:06
很喜庆的帖子,同贺鱼儿生日快乐!

小九同乐

雨中悄然 发表于 2023-2-19 12:48

红影 发表于 2023-2-18 10:08
悄然聪慧,弄了这么多鱼儿的头像,还有漂亮的烟花。这个又喜庆又漂亮。同祝鱼儿生日快乐

这个也是个学习贴,放点烟花喜庆喜庆{:4_173:}

雨中悄然 发表于 2023-2-19 12:49

海笑 发表于 2023-2-18 10:00
共祝鱼儿生日快乐!

替鱼儿感谢

雨中悄然 发表于 2023-2-19 12:49

梦油 发表于 2023-2-18 09:21
很高兴和雨中悄然一起祝福语鱼儿生日快乐。

替鱼儿感谢,鱼儿生日快乐

雨中悄然 发表于 2023-2-19 12:50

庶民 发表于 2023-2-18 05:52
在此借这个帖子,也来祝福您,生日快乐,天天快乐。

替鱼儿感谢,鱼儿生日快乐

雨中悄然 发表于 2023-2-19 12:50

鱼儿 发表于 2023-2-18 01:11
谢谢悄然

{:4_176:}{:4_183:}生日快乐,丫头

马黑黑 发表于 2023-2-19 12:52

雨中悄然 发表于 2023-2-19 12:47
老师跑得好快

速度还行

雨中悄然 发表于 2023-2-19 12:57

马黑黑 发表于 2023-2-19 12:52
速度还行

你来了好,等会交份作业{:4_170:}
页: [1] 2
查看完整版本: 鱼儿生日快乐