We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have searched for a few topics on this but none of them had a simple and working solution or I couldn't manage. But it seems this has a simple solution yet I somehow couldn't do it. All I want is all these images in my array to be proportionally fit to a max width of 20 (which I believe that is resize(20,20) does) but I couldn't manage to call that function as the image is an array. I have tried all these three below the image() line but none of them worked cause it seems it locks them all to 20x20 pixel size. How can I manage this, thanks!
myImageArray[i].resize(20,0);
image(myImageArray[(int)random(5)].resize(20,0);
myImageArray.resize(20,0);
Here is my code;
PImage[] myImageArray = new PImage[20];
float px;
float py;
void setup() {
size(600, 600,P3D);
frameRate(30);
background(0);
for (int i=0; i<myImageArray.length; i++) {
myImageArray[i] = loadImage( "frag_" + i + ".jpg");
}
}
void draw() {
background(0); // For glitch effect
pushMatrix();
translate(px, py);
py+=1; // Glitch skip
for (int i=0; i<width; i+=25) {
for (int j=-3000; j<3000; j+=23) {
//for (int j=0; j<3000; j+=25) { // For glitch effect
image(myImageArray[(int)random(5)], i, j, 20, 20);
}
}
popMatrix();
}
Answers
For speed sake don’t use image with 5 parameters just with 3
Instead use resize in setup
I think the syntax is
image[i] = image[i].resize(20,20);
Usd 0 instead of 20 to make it proportional
20,0
Thanks, I have tried;
in the for loop in the setup but it gave type mismatch, void does not match with processing.core.PImage error. Wherever I call .resize function I get various errors :)
https://Processing.org/reference/PImage_resize_.html
https://Processing.org/reference/void.html
My code at the moment looks like this, I have added that .resize() but still all the images are 20,20 - what might I be doing wrong?
IN line 25 please remove the two last parameters
20,20
Yes, finally! Thanks.
this
same as
Actually I have tried those as well but didn't remove the 20,20 in draw... I thought this resize would override the arguments in image but it clearly doesn't :)
;-)
...and temporary resizing is almost always a bad idea (terrible for performance). With very few exceptions, don't resize in draw(), and don't use the 5-parameter image() unless it is a once-only call.
Many thanks for the bonus tips, this really helped a lot.