超级新加工,但作为一名视觉设计师,我不太了解编程,所以我不总是得到这种语言(双关语)。
我试图弄清楚如何上传至少2张被屏蔽的图像。我已经弄清楚如何以非随机的方式做到这一点,但是当我开始添加随机性时,我会陷入困境。
我可以通过电子邮件发送图片示例,因为我没有发布多个链接/图片的声誉。
我从这篇文章中发现了类似的问题/解决方案:
http://forum.processing.org/one/topic/load-random-image-please-help-a-noob.html
但是当我开始添加第二张图像时,定位开始变得不明朗。我尝试了几种图像模式(中心)和#39;的组合。和'图像(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
}
更新的输出图像
答案 0 :(得分:0)
你可能想稍微重写一下,这样你只需要加载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);
}