• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to create a looping animation that randomly selects images to appear in a set position

New Here ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Hi, I'm looking to create a looping animation that randomly selects images to appear in a set position - no scaling or moving, purely images that will randomly replace each other.

 

In this instance I have 20 faces, all the same size. The idea is for the faces to constantly change and be randomly replaced by one of the other faces, in an endless loop. Each instance would be for a set period of time - always .1 seconds.

 

Assuming this will be an expression that I'm not smart enough to figure out - thank you!

TOPICS
Expressions , How to , Scripting

Views

900

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2021 Apr 19, 2021

Here's a simple example. You could have a null layer named "Control" at the bottom of your layer stack with a slider control with this expression:

n = thisComp.numLayers-1;
dur = .1;
seedRandom(Math.floor(time/dur),true);
Math.floor(random(n))+1

All your face layers would be at the top of the layer stack, each with this opacity expression:

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

Hopefully that gets you headed in the right direction.

Votes

Translate

Translate
Community Expert ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

Here's a simple example. You could have a null layer named "Control" at the bottom of your layer stack with a slider control with this expression:

n = thisComp.numLayers-1;
dur = .1;
seedRandom(Math.floor(time/dur),true);
Math.floor(random(n))+1

All your face layers would be at the top of the layer stack, each with this opacity expression:

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

Hopefully that gets you headed in the right direction.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

BTW, if you need to ensure that the same face doesn't come up twice in a row, you could switch to this for the control layer's slider expression:

n = thisComp.numLayers-1;
dur = .1;
seg = Math.floor(time/dur);
seedRandom(index,true);
idx = Math.floor(random(n));
for (i = 0; i <= seg; i++){
  idx += Math.floor(random(1,n-1));
  idx %= n;
}
idx+1

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 26, 2023 Oct 26, 2023

Copy link to clipboard

Copied

LATEST

This is exactly what iv been looking for thanks!
I have one additional request, How would i now fade each random face to the next instead of just snapping?

So like a specified fade out time between each face, and would that go in each of the face layers or the control null layer?
Thank you

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

This worked perfectly, thank you so much Dan - appreciate it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines