使用canvas画美队盾牌

代码如下:

<canvas class="mycanvas" width="500" height="500">
            你的浏览器不支持canvas
        </canvas>
        <script type="text/javascript">
            let mycanvas = document.querySelector('.mycanvas');
            let c = mycanvas.getContext('2d');
            //为了防止样式覆盖,从外往里画
            //画一个大圆
            c.beginPath();
            c.arc(250, 250, 160, 0, Math.PI * 2);
            c.fillStyle = "#e0dedf";
            c.fill();
            c.lineWidth = 30;
            c.strokeStyle = 'rgb(196,30,58)';
            c.stroke();

            //画一个小圆
            c.beginPath();
            c.arc(250, 250, 100, 0, Math.PI * 2);
            c.fillStyle = "rgb(0,43,127)";
            c.fill();
            c.lineWidth = 30;
            c.strokeStyle = 'rgb(196,30,58)';
            c.stroke();

            //画五角星
            c.beginPath();
            for(let i = 0; i < 5; i++) {
                c.lineTo(Math.cos((18 + i * 72) / 180 * Math.PI) * 80 + 250, -Math.sin((18 + i * 72) / 180 * Math.PI) * 80 + 250);
                c.lineTo(Math.cos((54 + i * 72) / 180 * Math.PI) * 32 + 250, -Math.sin((54 + i * 72) / 180 * Math.PI) * 32 + 250);
            }
            c.closePath();
            c.fillStyle = "#e0dedf";
            c.fill();
            c.lineWidth = 1;
            c.strokeStyle = 'rgb(0,43,127)';
            c.stroke();

我这里只画了2个圆,只是把这两个圆的画笔宽度调大点,就形成了4个圆的效果
这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值