canvas绘制交通标志
时间: 2023-12-09 07:34:16 浏览: 27
以下是使用canvas绘制交通标志的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Canvas绘制交通标志</title>
<style type="text/css">
canvas {
border: 1px solid #000;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="200" height="200"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
// 绘制圆形
ctx.beginPath();
ctx.arc(100, 100, 50, 0, 2*Math.PI);
ctx.fillStyle = "red";
ctx.fill();
// 绘制三角形
ctx.beginPath();
ctx.moveTo(100, 50);
ctx.lineTo(150, 150);
ctx.lineTo(50, 150);
ctx.closePath();
ctx.fillStyle = "white";
ctx.fill();
// 绘制矩形
ctx.beginPath();
ctx.rect(75, 75, 50, 50);
ctx.fillStyle = "blue";
ctx.fill();
</script>
</body>
</html>
```