arcTo

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>arcTo示意</title>
  
</head>
<body>
    <canvas >       size控制n角星的大小

       */
       function createStar(context,n,dx,dy,size) {
           //开始创建路径
           context.beginPath();
           var dig = Math.PI / n * 4;
           for (var i = 0; i < n; i++) {
               var x = Math.sin(i * dig);
               var y = Math.cos(i * dig);
               context.lineTo(x * size + dx, y * size + dy);
            
           }
           context.closePath();
       }
       var canvas = document.getElementById("ourCanvas");
       var ctx = canvas.getContext("2d");
       createStar(ctx, 3, 60,60, 50);
       ctx.fillStyle = "#ff0";
       ctx.fill();

       createStar(ctx, 5, 100, 150, 60);
       ctx.fillStyle = "#f00";
       ctx.fill();

       createStar(ctx, 9, 100,280, 80);
       ctx.fillStyle = "#ccc";
       ctx.fill();
    </script>
</body>
</html>

相关文章:

  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-10-27
  • 2021-09-18
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2021-10-20
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
相关资源
相似解决方案