|
|

楼主 |
发表于 2024-5-4 18:35
|
显示全部楼层
本帖最后由 马黑黑 于 2024-5-4 18:39 编辑
代码
- <style>
- #papa { margin: 20px auto; width: 760px; height: 560px; background: linear-gradient(lightblue, tan); }
- #canv { display: block; position: absolute; background: #000; mix-blend-mode: screen; }
- </style>
- <div id="papa"><canvas id="canv"></canvas></div>
- <script>
- var ctx = canv.getContext('2d');
- let total = 50, r = 2, particles = [];
- let ww = canv.width = papa.offsetWidth, hh = canv.height = papa.offsetHeight;
- for (var i = 0; i < total; i ++) {
- let x = Math.random() * ww,
- y = Math.random() * hh,
- v = Math.random() * 0.5 + 0.5,
- color = 'rgba(255,255,255,.5)';
- particles.push({x: x, y: y, r: r, v: v, color: color});
- }
- var draw = (x,y,r,color) => {
- ctx.save();
- ctx.fillStyle = color;
- ctx.beginPath();
- ctx.arc(x, y, r, 0, 2 * Math.PI);
- ctx.fill();
- ctx.restore();
- };
- var move = () => {
- ctx.fillStyle = 'rgba(0, 0, 0, .1)';
- ctx.fillRect(0, 0, ww, hh);
- particles.forEach(p => {
- draw(p.x, p.y, p.r, p.color);
- p.x += p.v;
- p.y += p.v;
- if (p.x > ww) p.x = 0;
- if (p.y > ww) p.y = 0;
- });
- requestAnimationFrame(move);
- };
- move();
- </script>
复制代码
|
评分
-
| 参与人数 1 | 威望 +50 |
金钱 +100 |
经验 +50 |
收起
理由
|
红影
| + 50 |
+ 100 |
+ 50 |
赞一个! |
查看全部评分
|