Getting GIFs to Play in a Random Order

Hi all,

I’m relatively new to p5 and coding generally. I’m currently working on a project which requires several GIFs to play one after another in a random order. I understand that arrays might be the way to go but I’m not too sure so any ideas or examples would be welcome! The GIFs have to play in a random order continuously (i.e. without restarting the sketch to get a new GIF to play).

Thanks,

Tom

I’d start by breaking your problem down into smaller steps. For example, can you write a simple sketch that just shows 3 gifs in order? Get that working perfectly before moving on to the next step. Good luck!

Some elements to look at when thinking about random ordering:

https://p5js.org/reference/#/p5/random
https://p5js.org/reference/#/p5/shuffle

Depending on what kind of “random order” you want, these will have different effects – picking one at a time, vs. a shuffled deal. Do you ever want the same GIF to play twice in a row? If you shuffle, do you want to keep that order looping from that point on, or do you want it to change each cycle? These are the kinds of things you should think about.