老师检查一下
来源:3-8 编程练习
Raymond0913
2020-09-08 00:10:24
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Android</title>
<style>
canvas{background-color: lightpink;}
</style>
</head>
<body>
<canvas id="canvas" width="800" height="800">
您的浏览器不支持canvas
</canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
// 左天线
ctx.moveTo(300,50);
ctx.lineTo(350,200);
ctx.stroke();
ctx.beginPath();
// 右天线
ctx.moveTo(500,50);
ctx.lineTo(450,200);
ctx.stroke();
ctx.beginPath();
// 脸
ctx.strokeRect(300,200, 200,150);
ctx.beginPath();
//左边耳朵
ctx.strokeRect(270,230, 30,60);
ctx.beginPath();
// 右边耳朵
ctx.strokeRect(500,230, 30,60);
ctx.beginPath();
// 左眼
ctx.arc(350,250 ,15,0,2*Math.PI,true);
ctx.stroke();
ctx.beginPath();
// 右眼
ctx.arc(450,250,15,0,2*Math.PI,true);
ctx.stroke();
ctx.beginPath();
// 嘴
ctx.strokeRect(370,300, 60,20);
ctx.beginPath();
// 身体
ctx.strokeRect(350,350, 100,300);
ctx.beginPath();
// 左胳膊
ctx.strokeRect(100,450,250,30);
ctx.beginPath();
// 右胳膊
ctx.strokeRect(450,450,250,30);
ctx.beginPath();
// 左腿
ctx.strokeRect(360,650,30,250);
ctx.beginPath();
// 右腿
ctx.strokeRect(410,650,30,250);
ctx.beginPath();
</script>
</body>
</html>1回答
同学你好,效果是正确的,继续加油,祝学习愉快~