Skip to main content
Marc Rühl
Participating Frequently
February 9, 2010
Answered

Looping images really randomlyI

  • February 9, 2010
  • 1 reply
  • 3006 views

I need a constantly changing background for an animation. I use different drawings of the same background and loop them randomly, to avoid this looping look. Unfortunalety when I use random there are always two frames who show the same image. I try to solve this with valueAtTime but I always get an error-message with this expression.

temp0 = random();


temp1 = temp0.valueAtTime(time  - .1);


if (temp0 == temp1)

{ temp2 = temp0 + .1; }


else

{temp2 = temp0}


[temp2]

This topic has been closed for replies.
Correct answer Dan Ebberts

I tested it in a 10-second-comp, with a 10-image-loop-comp. And just at the end of the 10-sec-comp the images repeat, but then they repeat very often.


I just tried it on a 20 second comp (at 29.97 and 25 fps) and I don't get any repeated frames. I guess I'd need to see your project file to figure out why it doesn't work for you.

Dan

1 reply

Dan Ebberts
Community Expert
Community Expert
February 9, 2010

To avoid generating the same number twice in a row, you need to keep track of what's happened in the past. How many different images do you have? This expression assumes 10, but just edit the first line to match your number. This is one of those expressions that has to recalculate what's happened on each previous frame, so it might bog down if your comp is fairly long.

nFrames = 10;
seedRandom(index,true);
n = Math.floor(random(nFrames));

f = timeToFrames();

for (i = 0; i < f; i++){
  n += 1 +Math.floor(random(nFrames-1));
  n %= nFrames;
}

framesToTime(n)

Dan

Marc Rühl
Participating Frequently
February 9, 2010

Sorry. my english isn't that good. I guess I articulated it not right.

I have a comp, with, let's say a length of 10 frames. Every frame shows another picture. Now I want to loop it, but then you see that it repeats.

To avoid that, I activate time remapping and used random() to show another picture of the comp on every frame, randomly. Unfortunalety often there is the same picture on two frames one after another. I thought it would be a solution to check which number random() picked the frame before and if it's the same frame add 0.1, but my expression always gets an error-message.

As I said, my english isn't that good, I hope you can understand what I want to achieve, but thank you for your help.

Marc

Dan Ebberts
Community Expert
Community Expert
February 9, 2010

Your English is fine. Maybe it's me that's not articulating very well. :-)

The expression I posted is a time remapping expression that should do what you want. Did you try it?

Dan