如下代码:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <canvas id="canvas" style="border:1px solid #aaa;display:block;margin:50px auto;">
- 当前浏览器不支持Canvas,请更换浏览器后再试
- </canvas>
-
- <script>
- window.onload = function(){
-
- let canvas = document.getElementById("canvas");
- canvas.width = 800;
- canvas.height = 800;
-
- let context = canvas.getContext("https://cdn.jxasp.com:9143/image/2d");
- context.lineWidth = 10;
-
- context.beginPath();
- context.moveTo(100, 200);
- context.lineTo(300, 400);
- context.lineTo(100, 600);
- context.strokeStyle = "red";
- context.closePath();
- context.stroke();
- }
- </script>
-
- </body>
- </html>
运行截图如下:

修改代码如下:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- </head>
- <body>
- <canvas id="canvas" style="border:1px solid #aaa;display:block;margin:50px auto;">
- 当前浏览器不支持Canvas,请更换浏览器后再试
- </canvas>
-
- <script>
- window.onload = function(){
-
- let canvas = document.getElementById("canvas");
- canvas.width = 800;
- canvas.height = 800;
-
- let context = canvas.getContext("https://cdn.jxasp.com:9143/image/2d");
- context.lineWidth = 10;
-
- context.beginPath();
- context.moveTo(100, 200);
- context.lineTo(300, 400);
- context.lineTo(100, 600);
- context.fillStyle = "red";
- context.closePath();
- context.fill();
- }
- </script>
-
- </body>
- </html>
运行截图如下:

如上例子,closePath会让多边形封口。






![战神引擎传奇手游【1.76盛战传奇免授权版[摸摸登陆器]】最新整理Win系复古服务端+安卓苹果双端+GM授权物品后台+详细搭建教程](https://cdn.jxasp.com:9143/image/20251106/1B4E8594B3BEB90E8601D63A8A39CB0B.jpg)













