如何解决如何扭曲图像数组 - 处理
当我只有一张图片时,我已经完成了我想要的失真。
现在我必须将两个代码合并在一起,但是当 PImage 是一个数组时,我不知道该怎么做。
网格代码:
PImage img[];
int nPics;
int w,h;
void loadImages(){
for (int i = 0; i < nPics; i++) {
img[i] = loadImage("img_"+ nf(int(random(0,687)),3) + ".jpg");
imageMode(CORNERS);
}
}
void setup() {
size(1500,500);
nPics=27;
img = new PImage[nPics];
w=width/9;
h=height/3;
loadImages();
}
void mousepressed(){
loadImages();
}
void draw() {
background(0);
for (int i=0; i<nPics; i=i+3) {
int col = i/3;
for (int row=0; row<3; row++)
image(img[i+row],col*w,row*h,(col+1)*w,(row+1)*h);
}
}
波浪代码:
PImage myImage;
float speed1 = .01;
float speed2 = 5;
void setup()
{
size(1500,500);
myImage = loadImage("img_001.jpg");
}
void draw()
{
float distortion = map(mouseY,500,10);
for (int i = 0; i < myImage.width; ++i) {
copy(myImage,i,1,height,(int) (sin((millis()+i*speed2)*speed1)*distortion),height);
}
}
解决方法
如果您想将失真应用到整个画布,您可以只使用 copy()
而不使用 image 参数。这会导致它只是从画布上的当前内容进行复制。
您可以使用与 wave 代码中非常相似的 for
循环,只需省略 myImage
参数并让 i
从 0 变为 width
myImage.width
。然后将其放在 draw
代码中的 grid
块的末尾:
//global variables,include speed1 and speed2
void loadImages() {
//as in grid code
}
void setup() {
//as in grid code...
}
void draw() {
//everything from grid code...
float distortion = map(mouseY,500,10);
for (int i = 0; i < width; ++i) {
copy(i,1,height,//the rest...);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。