Beginner Question - Random Image From Array
in
Programming Questions
•
1 year ago
Hi, quick question. Seems like it should be simple, I just can't find an answer after googling and checking my book.
I have this code within my draw() right now:
PImage[] images = { i1, i2, i3 };
int rimage= int(random(images.length)); // this line is wrong
x = random(width);
y = random(height);
r = random(0, TWO_PI);
pushMatrix();
translate(x, y);
rotate(r);
image(rimage, -rimage.width/2, -rimage.height/2);
popMatrix();
}
I just need to know how to select a random PImage from the array, and pass it to the image function below.
Thank!
I have this code within my draw() right now:
PImage[] images = { i1, i2, i3 };
int rimage= int(random(images.length)); // this line is wrong
x = random(width);
y = random(height);
r = random(0, TWO_PI);
pushMatrix();
translate(x, y);
rotate(r);
image(rimage, -rimage.width/2, -rimage.height/2);
popMatrix();
}
I just need to know how to select a random PImage from the array, and pass it to the image function below.
Thank!
1