Skip navigation
Home/Support/

Forums

318 Views 10 Replies Latest reply: Feb 9, 2010 1:39 PM by Marc Rühl RSS
Marc Rühl Calculating status... 11 posts since
Jan 20, 2010
Currently Being Moderated

Feb 8, 2010 5:39 PM

Looping images really randomlyI

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]

  • Dan Ebberts Calculating status... 196 posts since
    Aug 11, 2002
    Currently Being Moderated
    1. Feb 9, 2010 10:09 AM (in response to Marc Rühl)
    Re: Looping images really randomlyI

    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

  • Dan Ebberts Participant 196 posts since
    Aug 11, 2002
    Currently Being Moderated
    3. Feb 9, 2010 10:52 AM (in response to Marc Rühl)
    Re: Looping images really randomlyI

    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

  • Dan Ebberts Participant 196 posts since
    Aug 11, 2002
    Currently Being Moderated
    5. Feb 9, 2010 11:22 AM (in response to Marc Rühl)
    Re: Looping images really randomlyI

    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

  • Dan Ebberts Participant 196 posts since
    Aug 11, 2002
    Currently Being Moderated
    7. Feb 9, 2010 11:51 AM (in response to Marc Rühl)
    Re: Looping images really randomlyI

    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

  • Dan Ebberts Participant 196 posts since
    Aug 11, 2002
    Currently Being Moderated
    9. Feb 9, 2010 1:12 PM (in response to Marc Rühl)
    Re: Looping images really randomlyI

    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

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points