1
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
2
您的浏览器不支持 HTML5 canvas 标签。
3
</canvas>
4
<script>
5
var c = document.getElementById("myCanvas");
6
var ctx = c.getContext("2d");
7
ctx.beginPath();
8
ctx.lineWidth = "5";
9
ctx.strokeStyle = "green"; // 绿色路径
10
ctx.moveTo(0, 75);
11
ctx.lineTo(250, 75);
12
ctx.stroke(); // 画
13
ctx.beginPath();
14
ctx.strokeStyle = "purple"; // 紫色的路径
15
ctx.moveTo(50, 0);
16
ctx.lineTo(150, 130);
17
ctx.stroke(); // 画
18
</script>