运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas - Draw a Shape</h1> <canvas id="myCanvas" width="200" height="125" style="border:1px solid #000000;"> Sorry, your browser does not support canvas. </canvas> <script> // Create a canvas const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); // Define a new path ctx.beginPath(); // Set start-point ctx.moveTo(20,20); // Set sub-points ctx.lineTo(100,20); ctx.lineTo(175,100); ctx.lineTo(20,100); // Set end-point ctx.lineTo(20,20); // Draw it ctx.stroke(); </script> </body> </html>