Skip navigation
Marc Rühl
Currently Being Moderated

Looping images really randomlyI

Feb 8, 2010 5:39 PM

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]

  • Currently Being Moderated
    Community Member
    Feb 9, 2010 10:09 AM

    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

    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 9, 2010 10:52 AM

    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

    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 9, 2010 11:22 AM

    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

    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 9, 2010 11:51 AM

    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

    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Feb 9, 2010 1:12 PM

    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

    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

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