处理 - 加载随机图像/定位
Processing – Loading random image / Positioning
处理方面的超级新手,但作为一名视觉设计师,我对编程了解不多,所以我并不总是能理解语言(双关语)。
我正在尝试弄清楚如何随机上传至少 2 张被屏蔽的图像。我已经想出如何以非随机的方式做到这一点,但是当我开始添加随机性时我被卡住了。
我可以通过电子邮件发送图片示例,因为我没有 post 发送多个链接/图片的名声。
我从这个 post 中发现了类似的问题/解决方案:
http://forum.processing.org/one/topic/load-random-image-please-help-a-noob.html
但是当我开始添加第二张图片时,定位开始出现问题。我在一些地方尝试了 'imageMode(CENTER)' 和类似 'image(img2, width/2, height/2)' 的一些组合,取得了不同程度的成功。
我相信这对某些人来说是显而易见的。
非常感谢您的帮助!
这是我现在所在的位置:
PImage img1, img2;
PImage imgMask;
PImage bg;
int rand1, rand2, rand3;
void setup() {
size(1024, 620);
smooth(4);
// imageMode(CENTER);
rand1 = int(random(0, 4));
takerandomimage("frag_" + nf(rand1, 3) + ".jpg");
imageMode(CENTER);
rand2 = int(random(5, 8));
takerandomimage("frag_" + nf(rand2, 3) + ".jpg");
imageMode(CENTER);
noLoop();
}
void takerandomimage(String fn) {
img1 = loadImage(fn); //LOAD RANDOM IMAGE
imgMask = loadImage("caps.png");
img1.mask(imgMask);
image(img1, 0, 0); //DISPLAY RANDOM IMAGE
img2 = loadImage(fn); //LOAD RANDOM IMAGE
imgMask = loadImage("extrudes.png");
img2.mask(imgMask);
image(img2, width/2, height/2); //DISPLAY RANDOM IMAGE
}
更新
PImage img1, img2;
PImage imgMask;
PImage bg;
int rand1, rand2;
void setup() {
size(1024, 620);
smooth(4);
bg = loadImage("1781.jpg");
imageMode(CENTER);
rand1 = int(random(0, 8));
takerandomimage("frag_" + nf(rand1, 3) + ".jpg");
rand2 = int(random(0, 8));
takerandomimage("frag_" + nf(rand2, 3) + ".jpg");
noLoop();
}
void takerandomimage(String fn) {
img1 = loadImage(fn); //LOAD RANDOM IMAGE
img2 = loadImage(fn); //LOAD RANDOM IMAGE
}
void draw() {
background(bg);
imgMask = loadImage("caps.png");
img1.mask(imgMask);
image(img1, width/2, height/2, width, height); //DISPLAY RANDOM IMAGE
imgMask = loadImage("extrudes.png");
img2.mask(imgMask);
image(img2, width/2, height/2, width, height); //DISPLAY RANDOM IMAGE
}
更新的输出图像
你可能想稍微重写一下,这样你只加载 img1/img2 一次,而不是在你点击 draw
之前多次加载,并在此过程中稍微优化其他 PImages:
PImage img1, img2, caps, extrudes, bg;
void setup() {
size(1024, 620);
smooth(4);
bg = loadImage("1781.jpg");
caps = loadImage("caps.png");
extrudes = loadImage("extrudes.png");
// Load two random images, and mask
// them according to what we want:
img1 = loadRandomImage(0, 4);
img1.mask(caps);
img2 = loadRandomImage(4, 8);
img2.mask(extrudes);
// set some sketch properties and then move on to draw()
imageMode(CENTER);
noLoop();
}
// this loads a file "frag_xxx.jpg" where xxx is a padded
// number between [start] and [end]:
PImage loadRandomImage(int start, int end) {
String filename = "frag_" + nf(int(random(start,end)), 3) + ".jpg";
return loadImage(filename);
}
// draw actually does almost nothing:
void draw() {
background(bg);
int w = width, h = height, w2 = width/2, h2 = height/2;
image(img1, w2, h2, w, h);
image(img2, w2, h2, w, h);
}
处理方面的超级新手,但作为一名视觉设计师,我对编程了解不多,所以我并不总是能理解语言(双关语)。
我正在尝试弄清楚如何随机上传至少 2 张被屏蔽的图像。我已经想出如何以非随机的方式做到这一点,但是当我开始添加随机性时我被卡住了。
我可以通过电子邮件发送图片示例,因为我没有 post 发送多个链接/图片的名声。
我从这个 post 中发现了类似的问题/解决方案:
http://forum.processing.org/one/topic/load-random-image-please-help-a-noob.html
但是当我开始添加第二张图片时,定位开始出现问题。我在一些地方尝试了 'imageMode(CENTER)' 和类似 'image(img2, width/2, height/2)' 的一些组合,取得了不同程度的成功。
我相信这对某些人来说是显而易见的。
非常感谢您的帮助!
这是我现在所在的位置:
PImage img1, img2;
PImage imgMask;
PImage bg;
int rand1, rand2, rand3;
void setup() {
size(1024, 620);
smooth(4);
// imageMode(CENTER);
rand1 = int(random(0, 4));
takerandomimage("frag_" + nf(rand1, 3) + ".jpg");
imageMode(CENTER);
rand2 = int(random(5, 8));
takerandomimage("frag_" + nf(rand2, 3) + ".jpg");
imageMode(CENTER);
noLoop();
}
void takerandomimage(String fn) {
img1 = loadImage(fn); //LOAD RANDOM IMAGE
imgMask = loadImage("caps.png");
img1.mask(imgMask);
image(img1, 0, 0); //DISPLAY RANDOM IMAGE
img2 = loadImage(fn); //LOAD RANDOM IMAGE
imgMask = loadImage("extrudes.png");
img2.mask(imgMask);
image(img2, width/2, height/2); //DISPLAY RANDOM IMAGE
}
更新
PImage img1, img2;
PImage imgMask;
PImage bg;
int rand1, rand2;
void setup() {
size(1024, 620);
smooth(4);
bg = loadImage("1781.jpg");
imageMode(CENTER);
rand1 = int(random(0, 8));
takerandomimage("frag_" + nf(rand1, 3) + ".jpg");
rand2 = int(random(0, 8));
takerandomimage("frag_" + nf(rand2, 3) + ".jpg");
noLoop();
}
void takerandomimage(String fn) {
img1 = loadImage(fn); //LOAD RANDOM IMAGE
img2 = loadImage(fn); //LOAD RANDOM IMAGE
}
void draw() {
background(bg);
imgMask = loadImage("caps.png");
img1.mask(imgMask);
image(img1, width/2, height/2, width, height); //DISPLAY RANDOM IMAGE
imgMask = loadImage("extrudes.png");
img2.mask(imgMask);
image(img2, width/2, height/2, width, height); //DISPLAY RANDOM IMAGE
}
更新的输出图像
你可能想稍微重写一下,这样你只加载 img1/img2 一次,而不是在你点击 draw
之前多次加载,并在此过程中稍微优化其他 PImages:
PImage img1, img2, caps, extrudes, bg;
void setup() {
size(1024, 620);
smooth(4);
bg = loadImage("1781.jpg");
caps = loadImage("caps.png");
extrudes = loadImage("extrudes.png");
// Load two random images, and mask
// them according to what we want:
img1 = loadRandomImage(0, 4);
img1.mask(caps);
img2 = loadRandomImage(4, 8);
img2.mask(extrudes);
// set some sketch properties and then move on to draw()
imageMode(CENTER);
noLoop();
}
// this loads a file "frag_xxx.jpg" where xxx is a padded
// number between [start] and [end]:
PImage loadRandomImage(int start, int end) {
String filename = "frag_" + nf(int(random(start,end)), 3) + ".jpg";
return loadImage(filename);
}
// draw actually does almost nothing:
void draw() {
background(bg);
int w = width, h = height, w2 = width/2, h2 = height/2;
image(img1, w2, h2, w, h);
image(img2, w2, h2, w, h);
}