canvas制作五角星

tech2024-12-28  6

<!DOCTYPE html> <html> <head> <meta http-equiv = "content-type" content = "text/html" charset = "utf-8"/> <title> 五角星 </title> <script> window.onload=function(){ var canvas=document.getElementById('canvas'); var cx=canvas.getContext("2d"); cx.fillStyle='rgba(255,0,0,1)'; cx.strokeStyle='black'; cx.moveTo(10,240); cx.lineTo(300,240); cx.lineTo(60,70); cx.lineTo(155,350); cx.lineTo(245,70); cx.lineTo(10,240); cx.fill(); cx.stroke(); } </script> </head> <body> <canvas id="canvas" width="400px" height="400px" style="background-color: rgb(241, 231, 241);"></canvas> </body> </html>

效果图如下:

最新回复(0)