zoukankan      html  css  js  c++  java
  • canvas 绘制坐标轴

    结果:

    代码:

    <!DOCTYPE html>
    <html>
    <head lang="en">
      <meta charset="UTF-8">
      <title></title>
      <style>
        body {
          text-align: center;
        }
        canvas {
          background: #ddd;
        }
      </style>
    </head>
    <body>
      <h3>绘制路径——直线</h3>
      <canvas id="c13" width="500" height="400"></canvas>
      <script>
        var ctx = c13.getContext('2d');
    
        //绘制X轴
        ctx.beginPath();
        ctx.moveTo(50, 350);
        ctx.lineTo(450, 350);
        ctx.lineTo(450-20, 350-20);
        ctx.moveTo(450, 350);
        ctx.lineTo(450-20, 350+20);
    
        //ctx.lineJoin = 'miter'; //线的连接处采用尖角
        //ctx.lineJoin = 'bevel'; //线的连接处采用方角
        ctx.lineJoin = 'round'; //线的连接处采用圆角
        ctx.lineWidth = 5;
        ctx.strokeStyle = '#0a0';
        ctx.stroke();
    
        //绘制Y轴
        ctx.beginPath();  //必须开始新路径
        ctx.moveTo(50, 350);
        ctx.lineTo(50, 50);
        ctx.lineTo(50-20, 50+20);
        ctx.moveTo(50, 50);
        ctx.lineTo(50+20, 50+20);
    
        ctx.strokeStyle = '#00f';
        ctx.stroke();
    
      </script>
    </body>
    </html>
  • 相关阅读:
    第三个Sprint冲刺第三天
    回答第1-17章
    阅读第13-17章
    阅读第10、11、12章
    阅读第8,9,10章
    作业5.2 5.3
    四则运算 测试与封装 5.1
    阅读第5-7章
    阅读1-5章
    我给队友做的汉堡包
  • 原文地址:https://www.cnblogs.com/web-fusheng/p/6906630.html
Copyright © 2011-2022 走看看