码迷,mamicode.com
首页 > 其他好文 > 详细

三角形加正方形

时间:2018-12-02 16:18:21      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:get   rgb   line   etc   head   端点   getc   title   nbsp   

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <canvas id="canvas" width="300" height="300"></canvas>
  <script>
  var canvas = document.getElementById(‘canvas‘);
var ctx = canvas.getContext(‘2d‘);

ctx.beginPath();
ctx.moveTo(100,100);
ctx.lineTo(200,100);
ctx.lineTo(200,200);
ctx.lineTo(100,200);
ctx.closePath();
  ctx.stroke();
ctx.fillStyle = ‘rgb(230, 148, 249)‘;
ctx.fill();
ctx.beginPath();
    //设置路径起点坐标
    ctx.moveTo(100, 100);
    //绘制直线线段到坐标点
    ctx.lineTo(200, 100);
    //绘制直线线段到坐标点
   ctx.lineTo(150, 30);
    //先关闭绘制路径。注意,此时将会使用直线连接当前端点和起始端点。
    ctx.closePath();
    //最后,按照绘制路径画出直线
    ctx.stroke();
    // 进行绘图处理
     ctx.fillStyle = ‘rgba(200,0,0,0.5)‘;
     // 填充路径
     ctx.fill();
  </script>
</body>
</html>

三角形加正方形

标签:get   rgb   line   etc   head   端点   getc   title   nbsp   

原文地址:https://www.cnblogs.com/xiaoyueyuedeboke/p/10053583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!