| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 |
[复位日记]
网站统计
·今日访问 : 14
·页面点击 : 20
·当前在线 : 4
2025年6月25日 星期三[阅读 176]
在canvas中绘制横向、纵向色块纹理的函数:
- function drawTexture (w, h, colors, toRight = true) {
- const canv = document.createElement('canvas');
- canv.width = w;
- canv.height = h;
- const ctx = canv.getContext('2d');
- const len = colors.length;
- for (let j = 0; j < len; j ++) {
- ctx.fillStyle = colors[j];
- toRight ? ctx.fillRect(w / len * j, 0, w / len, h) : ctx.fillRect(0, h / len * j, w, h / len);
- }
- return canv;
- }
参数:
① w : 必须,canvas预设宽度;
② h :必须,canvas预设高度;
③ colors :必须,颜色数组;
④ toRight :可选,默认 true,向右平铺,false 向下平铺
发表评论:

