canvas绘制扳手
时间: 2023-08-03 19:10:18 浏览: 50
好的,下面是一个简单的canvas绘制扳手的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Canvas绘制扳手</title>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="400" height="300"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
// 扳手的柄
ctx.beginPath();
ctx.moveTo(50, 100);
ctx.lineTo(50, 260);
ctx.lineWidth = 20;
ctx.strokeStyle = "#444";
ctx.stroke();
// 扳手的头
ctx.beginPath();
ctx.arc(200, 180, 80, 0, 2*Math.PI);
ctx.fillStyle = "#DDD";
ctx.fill();
// 扳手的上下两个螺丝头
ctx.beginPath();
ctx.arc(160, 120, 20, 0, 2*Math.PI);
ctx.fillStyle = "#444";
ctx.fill();
ctx.beginPath();
ctx.arc(240, 240, 20, 0, 2*Math.PI);
ctx.fillStyle = "#444";
ctx.fill();
</script>
</body>
</html>
```
运行代码后,可以看到canvas中绘制了一个扳手的图形。这只是一个简单的示例,你可以根据自己的需求进行修改和扩展。