马黑PHP整站系统

1234567
891011121314
15161718192021
22232425262728
2930     

[复位日记]

最新评论

风云
悄然
飞飞
马黑
悄然

网站统计

·今日访问 : 14
·页面点击 : 20
·当前在线 : 4

2025年6月25日 星期三[阅读 176]

在canvas中绘制横向、纵向色块纹理的函数:

  1. function drawTexture (w, h, colors, toRight = true) {
  2.     const canv = document.createElement('canvas');
  3.     canv.width = w;
  4.     canv.height = h;
  5.     const ctx = canv.getContext('2d');
  6.     const len = colors.length;
  7.     for (let j = 0; j < len; j ++) {
  8.         ctx.fillStyle = colors[j];
  9.         toRight ? ctx.fillRect(w / len * j, 0, w / len, h) : ctx.fillRect(0, h / len * j, w, h / len);
  10.     }
  11.     return canv;
  12. }
参数:
    ① w : 必须,canvas预设宽度;
    ② h :必须,canvas预设高度;
    ③ colors :必须,颜色数组;
    ④ toRight :可选,默认 true,向右平铺,false 向下平铺

2025': 前一则  下一则    

发表评论:

       

Copyright © 2023 All Right Reserved 马黑PHP文章管理整站系统v1.8
联系我们: gxblk@163.com