0
点赞
收藏
分享

微信扫一扫

h5-随机画圆(随机颜色、随机大小)

我是小小懒 2022-03-30 阅读 76

效果:
在这里插入图片描述
代码

    for(var i=0;i<50;i++){
        ctx.beginPath();
        ctx.arc(Math.random()*400,Math.random()*400,Math.random()*50,0,Math.PI*2);
        //设置透明度
        ctx.globalAlpha = Math.random()*0.2;
        //随机生成颜色
        ctx.fillStyle="rgba("+Math.random()*255+","
            +Math.random()*255+","+Math.random()*255;
        ctx.fill();
        ctx.stroke();
    }

注意:

  • 随机生成颜色
  • 设置透明度
  • 利用Math.random() 生成随机0-1的数字
举报

相关推荐

0 条评论