首页 > 其他 > 详细

canvas绘制矩形

时间:2019-02-08 21:00:04      阅读:202      评论:0      收藏:0      [点我收藏+]

canvas绘制矩形

  1. 方法

    fillRect(x, y, width, height)           画一个实心的矩形
    clearRect(x, y, width, height)          清除一块儿矩形区域
    strokeRect(x, y, width, height)         画一个带边框的矩形
    rect(x, y, width, height)               直接画一个矩形
  2. 画一个矩形

    const canvas = document.getElementById(‘canvas‘);
    const ctx = canvas.getContext(‘2d‘);
    
    ctx.fillRect(25, 25, 100, 100);
    ctx.clearRect(45, 45, 60, 60);
    ctx.strokeRect(50, 50, 50, 50);
  3. 画一个矩形(使用rect)

    ctx.rect(50,50,200,100);    
    ctx.fill();

canvas绘制矩形

原文:https://www.cnblogs.com/ye-hcj/p/10356718.html

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