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

Looping images really randomlyI

Explorer ,
Feb 08, 2010 Feb 08, 2010

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]

TOPICS
Expressions
2.9K
Translate
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 , Feb 09, 2010 Feb 09, 2010

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

Translate
Community Expert ,
Feb 09, 2010 Feb 09, 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

Translate
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
Explorer ,
Feb 09, 2010 Feb 09, 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

Translate
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 ,
Feb 09, 2010 Feb 09, 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

Translate
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
Explorer ,
Feb 09, 2010 Feb 09, 2010

Ya, I tried it, but there were several sequent frames which showed the same picture, therefore and cause I didn't understand the expression I guessed I didn't make clear what I want to achieve.

Translate
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 ,
Feb 09, 2010 Feb 09, 2010

Hmmm.... I don't know why it's not working for you. I just tried it and I don't get any repeated frames as far out as I checked (200+ frames or so).

Dan

Translate
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
Explorer ,
Feb 09, 2010 Feb 09, 2010

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.

Translate
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 ,
Feb 09, 2010 Feb 09, 2010

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

Translate
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
Explorer ,
Feb 09, 2010 Feb 09, 2010

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.

Translate
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 ,
Feb 09, 2010 Feb 09, 2010

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

Translate
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
Explorer ,
Feb 09, 2010 Feb 09, 2010
LATEST

ah ok. Thank you.

Translate
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