Random image from URL
in
Contributed Library Questions
•
1 year ago
Hello.
I'm writing some code to pull images from a url and then randomly display one when mousePressed. So far I've got:
- PImage fragment;
- int rand;
- void setup() {
- size(800, 600);
- rand = int(random(0, 9));
- randomimage("http://samuelcox.net/random/frag_" + nf(rand, 3) + ".jpg");
- }
- // RANDOM LOAD FUNCTION
- void randomimage(String fn) {
- fragment = loadImage(fn); //LOAD RANDOM IMAGE
- }
- void draw()
- {
- image(fragment, 0, 0);
- if (mousePressed) {
- image(fragment, 0, 0);
- }
- }
This loads one image, but when mousePressed doesn't pull another one. I'm guessing thats because the randomimage is in void setup? Any help to do this would be appreciated!
1