老师请检查
来源:3-8 编程练习
小丁同学ddd
2020-03-24 19:56:45
请问画图找定位有什么好方法吗?这样一点点试好麻烦
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
canvas{background-color:lightblue;}
</style>
</head>
<body>
<canvas id="canvas" width="800" height="800">
您的浏览器不支持canvas
</canvas>
<script>
//在此处写出代码
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.strokeRect(300,180,200,130);
ctx.beginPath();
//左眼
ctx.arc(350,230,15,0,2*Math.PI,true);
ctx.stroke();
ctx.beginPath();
//右眼
ctx.arc(450,230,15,0,2*Math.PI,true);
ctx.strokeRect(365,260,70,30);
//左天线
ctx.moveTo(370,180);
ctx.lineTo(300,100);
//右天线
ctx.moveTo(430,180);
ctx.lineTo(500,100);
//左耳
ctx.strokeRect(270,200,30,60);
//右耳
ctx.strokeRect(500,200,30,60);
//身体
ctx.strokeRect(330,310,135,200);
//左手
ctx.strokeRect(180,360,150,20);
//右手
ctx.strokeRect(465,360,150,20);
//左腿
ctx.strokeRect(350,510,20,150);
//右腿
ctx.strokeRect(425,510,20,150);
ctx.stroke();
</script>
</body>
</html>
1回答
同学你好,代码效果正确。另,没有简单的办法哦。因为现在是初学阶段,我们需要通过这个练习去掌握canvas的基本知识。其实实际开发中很少使用canvas去绘图,或者这些数据是ui设计师直接提供哦。
如果我的回答帮到了你,欢迎采纳,祝学习愉快~