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]
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
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
I changed the fps of the comp from 12 to 25. I don't know why, but now it works. Is there something what could affect this in the expression?
Anyway, thank you a lot for your help. Now I try to figure out what the expression actually does
. But can you tell me why my expression doesn't work?
Again, thank you a lot.
Your original expression doesn't work mainly because an expression can't use valueAtTime() to get a value that it calculated previously. The only way an expression can retrieve a previous result for the property to which it is applied is to recalculate it. You can't even apply valueAtTime() to anything other than a property, which is why you got the error message when you tried to apply it to a variable.
Dan
North America
Europe, Middle East and Africa
Asia Pacific
Copyright © 2012 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).