|
|

楼主 |
发表于 2022-8-23 23:00
|
显示全部楼层
代码:
- <style>
- #canv { margin: auto; display: block; position: relative; border: 1px solid; }
- </style>
- <canvas id="canv" width="600" height="400"></canvas>
- <script>
- let ctx = canv.getContext('2d');
- let num = (end,start) => Math.floor(Math.random() * (end - start) + start);
- (function draw() {
- ctx.clearRect(0, 0, canv.width, canv.height);
- ctx.shadowOffsetX = 4;
- ctx.shadowOffsetY = 4;
- ctx.shadowBlur = 8;
- ctx.shadowColor = 'black';
- for(j =0; j < 100; j ++) {
- ctx.fillStyle = 'hsla(' + num(0,360) + ', 100%, 50%, 0.65)';
- let r = num(20, 5),
- x = num(r, canv.width - r),
- y = num(r, canv.height - r);
- ctx.beginPath();
- ctx.arc(x, y, r, 0, Math.PI * 2);
- ctx.fill();
- }
- ctx.fillStyle = 'darkgreen';
- ctx.font = 'bold 60px sans-serif';
- ctx.textAlign = 'center';
- ctx.textBaseline = 'middle';
- ctx.fillText('花潮论坛', canv.width / 2, canv.height / 2);
- })();
- </script>
复制代码
|
|