【发布时间】:2021-05-30 09:58:47
【问题描述】:
我正在尝试构建一个网格,其中每个单元格都由处理中的随机图像填充。我在数据文件夹中有 500 多张名为 img_xxx.jpg 的图像。到目前为止,我已经完成了一个网格,其中显示的图像是随机的,但每个单元格的图像都是相同的。希望你能帮助我!谢谢。
final static byte GRID = 6, NUM = GRID*GRID;
PImage img;
int rand;
void setup() {
size(400, 400);
noLoop();
smooth();
background(0);
final PImage[] imgs = new PImage[NUM];
final int tileW = width/GRID, tileH = height/GRID;
rand = int(random(0,687));
for (int idx=0; idx!=NUM; imgs[idx++] = loadImage("img_" + nf(rand,3)+ ".jpg"));
for (int idx=0, row=0; row!=GRID; ++row) for (int col=0; col!=GRID;
image(imgs[idx++], col++*tileW, row*tileH, tileW, tileH));
img = get();
}
void draw() {
background(img);
}
【问题讨论】:
标签: image-processing processing