首页 > 其他 > 详细

canvas生成扇形

时间:2020-05-26 13:35:35      阅读:38      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
  </style>

</head>

<body>
    <img src="" id="img">

  <script>


   function createShanImg(angle, color, strokeColor) {
        var angle = +angle;
        var canvas = document.createElement("canvas");
        canvas.width = 252;

        canvas.height = 252;
        var ctx = canvas.getContext("2d");
        // 开始一条新路径
        ctx.beginPath();

        // 位移到圆心,方便绘制
        ctx.translate(126, 126);
        // 移动到圆心
        ctx.moveTo(0, 0);
        // 绘制圆弧
        ctx.arc(
          0,
          0,
          126 - 10,
          (Math.PI / 180) * (80 + 180 + angle),
          (Math.PI / 180) * (100 + 180 + angle),
          false
        );
        // 闭合路径
        ctx.closePath();
        ctx.strokeStyle = strokeColor;
        ctx.fillStyle = color;
        // ctx.fillStyle = "rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
        ctx.globalAlpha = "0.7";
        ctx.lineWidth = 2;
        ctx.stroke();
        ctx.fill();
        return canvas.toDataURL("image/png");
      }
  document.getElementById("img").src=createShanImg(100, ‘blue‘, ‘blue‘)



    
  </script>
</body>

</html>

canvas生成扇形

原文:https://www.cnblogs.com/liuhao-web/p/12465636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!