Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Luke Hale on April 10, 2007 at 7:45 pm

    I want a layer to occupy one of four rotation values and for the rotation of the layer to occupy one of these values randomly over time. The expression is came up with will probably explain this better,

    w = random(4);
    if ( w >= 0 && w > 1 ) 90
    if ( w >= 1 && w > 2 ) 180;
    if ( w >= 2 && w > 3 ) 270;
    if ( w >= 3 && w >= 4 ) 0;

    The biggest problem is the changes are far to quick; once a frame. I would like the changes to be about twice a second. Any one know how i can do so? Also another problem is at some points in time the rotation value is the random value i.e. between 0-4, i assume this is because some numbers fall outside my inequality ranges, but can’t spot the leak?

    I then want to arrange duplicates of this layer in a grid so that each of them is changing differently, is there a better way than just offsetting the layers in time? Or can i use something like random.seed so that each is changing differently?

    Thanks a lot

    Luke

    Darby Edelen replied 19 years ago 4 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    April 10, 2007 at 7:58 pm

    Try this:

    freq = 2; //2 changes per second

    cycle = Math.floor(time*freq);
    seedRandom(cycle,true);
    ((Math.floor(random(4)) + 1)%4)*90

    Dan

  • Colin Braley

    April 10, 2007 at 8:04 pm

    GIve this a go:

    //–
    duration = .5;
    seedRandom( Math.floor(time/duration) , true );
    Math.round( random(0, 4) – 1) * 90
    //–
    ~Colin

  • Luke Hale

    April 10, 2007 at 8:05 pm

    Perfect! Thanks a lot Dan.

    Luke

  • Darby Edelen

    April 10, 2007 at 10:34 pm

    [Luke Hale] “once a frame”

    random() evaluates to a new value every frame.

    You’ve already had some more elegant solutions offered, but another possibility is to use this expression:

    posterizeTime(2);

    before any of your other lines, this will cause AE to only update the values from the remainder of the expression 2 times per second.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy