Skip to main content
Participant
June 28, 2023
Question

Show images at random for a random time between 1 an 3 seconds

  • June 28, 2023
  • 1 reply
  • 403 views

hey community (sorry in advance i am fairly newisch to after effects)

 

here is my problem: 

I have 12 images (pngs with transperancies) in composition, and I want them to be shown randomly. When one image is displayed, no other of the 11 images should be shown. A image should be displayed for a random duration between 1 second and 3 seconds. There should always be one image displayed in the composition, and this functionality should continue for the duration of the composition.

 

i guess it could work if you have some coding knowlege (i dont have any) 

i hope some of you can help me (did try chatGPT this sucker makes me crazy)

 

all the best.

 

This topic has been closed for replies.

1 reply

Dan Ebberts
Community Expert
Community Expert
June 28, 2023

You could set it up so that your image layers are at the top of the layer stack (layers 1 through 12) and below that you would add a null named "Control", add a Slider Control and add this expression to the slider:

minDur = 1;
maxDur = 3;
numImages = 12;
seedRandom(index,true);
image = Math.floor(random(numImages));
tNext =0;
while (tNext <= time){
  tPrev = tNext;
  tNext += random(minDur,maxDur);
  image = (image + Math.floor(random(numImages-1)))%numImages
}
image+1

Then you would add this expression to the Opacity of each of your image layers:

idx = thisComp.layer("Control").effect("Slider Control")("Slider");
idx == index ? 100 : 0

Something like that.

Dan Ebberts
Community Expert
Community Expert
June 28, 2023

Sorry, there's a bug in the slider expression. This should work better:

minDur = 1;
maxDur = 3;
numImages = 12;
seedRandom(index,true);
image = Math.floor(random(numImages));
tNext =0;
while (tNext <= time){
  tPrev = tNext;
  tNext += random(minDur,maxDur);
  image = (image + Math.floor(random(1,numImages)))%numImages
}
image+1
Participant
June 29, 2023

Wow! first of all thanks for the super fast response time!! 

 

and second it works like a charme! you are one (or more idk) awesome person(s)!!

thanks for your awesomeness!! 

all the best.