canvas画布用圆,直线画一只可爱的哆啦A梦大头

canvas画布用圆,直线画一只可爱的哆啦A梦大头

图片
在这里插入图片描述

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            *{
                margin: 0;
                padding: 0;
            }
			body{
				background: #ccc;
			}
            .box{
                width: 600px;
                height: 600px;
                margin: 0 auto;
				background: #fff;
            }
        </style>
    </head>
    <body>
        <div class="box">
            <canvas id="canvas" width="600px" height="600px"></canvas>
        </div>
        <script type="text/javascript">
            var canvas = document.getElementById("canvas");
            var ctx = canvas.getContext('2d');
            /*画头*/
			
			ctx.beginPath();
			ctx.lineWidth = 4;
			ctx.strokeStyle = '#000';
			ctx.fillStyle = '#0bb0da';
			ctx.arc(300,175,175,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.stroke();
			ctx.closePath();
			//脸
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.fillStyle = '#fff';
			ctx.arc(300,250,120,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.stroke();
			ctx.clearRect(200,320,200,300);
			ctx.closePath();
			//眼睛
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.fillStyle = '#fff';
			ctx.arc(260,160,40,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.stroke();
			ctx.closePath();
			
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.fillStyle = '#fff';
			ctx.arc(350,160,40,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.stroke();
			ctx.closePath();
            //眼珠
			ctx.beginPath();
			ctx.fillStyle = '#000';
			ctx.arc(270,180,10,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.closePath();
			
			ctx.beginPath();
			ctx.fillStyle = '#000';
			ctx.arc(340,180,10,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.closePath();
			//鼻子
			ctx.beginPath();
			ctx.fillStyle = '#d05823';
			ctx.arc(300,220,25,0,Math.PI/180*360);
			ctx.fill();//颜色填充
			ctx.closePath();
			//胡子
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(300,250);
			ctx.lineTo(300,300);
			ctx.stroke();
			ctx.closePath();
			//左边小胡子
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(270,260);
			ctx.lineTo(220,250);
			ctx.stroke();
			ctx.closePath();
			
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(270,270);
			ctx.lineTo(220,275);
			ctx.stroke();
			ctx.closePath();
			
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(270,280);
			ctx.lineTo(220,300);
			ctx.stroke();
			ctx.closePath();
			//右边小胡子
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(330,260);
			ctx.lineTo(380,250);
			ctx.stroke();
			ctx.closePath();
			
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(330,270);
			ctx.lineTo(380,275);
			ctx.stroke();
			ctx.closePath();
			
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(330,280);
			ctx.lineTo(380,300);
			ctx.stroke();
			ctx.closePath();
			//嘴
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.moveTo(270,310);
			ctx.lineTo(330,310);
			ctx.stroke();
			ctx.closePath();
			//衣服下面
			ctx.beginPath();
			ctx.lineWidth = 1;
			ctx.strokeStyle = '#000';
			ctx.fillStyle = '#d05823';
			ctx.fillRect(180,320,240,40);
			ctx.stroke();
			ctx.fill();
			ctx.closePath();
        </script>
    </body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值