用js画一个小人
时间: 2023-11-27 10:49:48 浏览: 23
好的,下面是一个简单的用JS画小人的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>JS Draw a Person</title>
<style>
canvas {
border: 1px solid #ccc;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="200" height="200"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.strokeStyle = "#000";
ctx.lineWidth = 2;
// 画头
ctx.beginPath();
ctx.arc(100, 50, 30, 0, 2 * Math.PI);
ctx.stroke();
// 画身体
ctx.beginPath();
ctx.moveTo(100, 80);
ctx.lineTo(100, 140);
ctx.stroke();
// 画左腿
ctx.beginPath();
ctx.moveTo(100, 140);
ctx.lineTo(70, 180);
ctx.stroke();
// 画右腿
ctx.beginPath();
ctx.moveTo(100, 140);
ctx.lineTo(130, 180);
ctx.stroke();
// 画左手
ctx.beginPath();
ctx.moveTo(100, 100);
ctx.lineTo(70, 120);
ctx.stroke();
// 画右手
ctx.beginPath();
ctx.moveTo(100, 100);
ctx.lineTo(130, 120);
ctx.stroke();
</script>
</body>
</html>
```
运行后可以看到一个简单的小人图形。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)