Upload random Shape

Hi everyone, I am trying to upload randomly svg files with this method:
The pictures are picked to form 3 different groups
it should be displayed 3 images at time.
[i did an example to be sure]

That’s what I have done (just to pick one shape) but sometimes it gives me this error:
(even if in the folder all the file are named right)

void setup() {
  size(800, 500);
  
  PShape fragment;
float a = random(1,6);
int fragNumber = int (a);
  fragment = loadShape("frag" + fragNumber + ".svg");
  shapeMode(CENTER);
  shape(fragment, width/2, height/2, 100, 100);
  smooth();
}

Please, can you format your code above?
To do that, edit your post, select your code and click on the </> icon on top of the edition frame.

Also, can you create a github repository with a working example with your data folder and some pictures in it?

You also say that you are getting an error. Can you precise wich one?

If you do that people will be more willing to help you :slight_smile:

3 Likes

What the error message is saying is that it can’t find a file called “frag2.svg” to read, which means that it probably isn’t in the folder. In your sketch folder, have you got files called:

  • frag1.svg
  • frag2.svg
  • frag3.svg
  • frag4.svg
  • frag5.svg

as if any of them are missing, then then you will get errors thrown at you.

Also (though you might already be aware of this), the int() function always rounds down so the second number in your random function should be 1 more than the biggest number in your files (e.g if there are 6 files you want this number to be 7).