帆布画脸

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>


       <canvas width="800" height="600" style="border:1px solid #c3c3c3" id="ocanvas">
            对不起你的浏览器不支持
       </canvas>
       <input type="submit" value="按钮">
       <script>
           var ocanvas=document.getElementById("ocanvas");
           var ctx= ocanvas.getContext("2d");
           var input=document.getElementsByTagName("input")[0];
           var num=0;
           input.οnclick=function () {
               ctx.clearRect(300,350,200,100);
               if(num==0){
                   num++;
                   ctx.beginPath();
                   ctx.arc(400,450,90,-Math.PI/6,-Math.PI/6*5,true);
                   ctx.strokeStyle="black";
                   ctx.stroke();
                   ctx.closePath();
               }
               else if(num==1){
                   num--;
                   ctx.beginPath();
                   ctx.arc(400,350,90,Math.PI/6,Math.PI/6*5,false);
                   ctx.strokeStyle="black";
                   ctx.stroke();
                   ctx.closePath();
               }
           };

           ctx.beginPath();
           ctx.arc(400,300,200,0,Math.PI*2,true);
           ctx.fillStyle="white";
           ctx.stroke();
           ctx.closePath();

           ctx.beginPath();
           ctx.arc(325,240,50,0,Math.PI*2,true);
           ctx.fillStyle="black";
           ctx.fill();
           ctx.closePath();

           ctx.beginPath();
           ctx.arc(325,240,51,0,Math.PI*2,true);
           ctx.strokeStyle="red";
           ctx.stroke();
           ctx.closePath();

           ctx.beginPath();
           ctx.arc(475,240,50,0,Math.PI*2,true);
           ctx.fillStyle="black";
           ctx.fill();
           ctx.closePath();

           ctx.beginPath();
           ctx.arc(475,240,51,0,Math.PI*2,true);
           ctx.strokeStyle="red";
           ctx.stroke();
           ctx.closePath();

           ctx.beginPath();
           ctx.arc(400,350,90,Math.PI/6,Math.PI/6*5,false);
           ctx.strokeStyle="black";
           ctx.stroke();
           ctx.closePath();
       </script>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值