Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Prevent subsequent random value

  • Prevent subsequent random value

  • Marvin Claußen

    May 22, 2022 at 4:58 pm

    Hi! I have a precomp of 5 shapes with 4 different variants. Each variant runs for 6 frames, and they’re next to each other in the timeline. So shape 1 runs from 0-1sec, shape 2 runs from 1-2 sec, etc.
    I’m trying to randomize the timeremap of this precomp, to try to get different patterns (without repeating shapes.

    So for example: random remaps time to 1, the shape on the next frame can be 2,3,4,5
    then, if 2 was generated, the next one can be 1,3,4,5, etc.

    Each shape should be visible for 2 frames, which is why I’m using posterizeTime.

    I’ve been trying a few approaches, but nothing really works, so I’m hoping you can help me!

    posterizeTime(12);
    const min = 0;
    const max = 120;
    const offset = 24;
    let currentValue = timeToFrames(timeRemap);
    let newValue = Math.round(random(min, max));
    while (newValue <= currentValue + offset && newValue >= currentValue – offset) {
    newValue = Math.round(random(min,max));
    }
    framesToTime(newValue)

    and also like this

    const min = 0;
    const max = 4;
    posterizeTime(12);
    const currentShape = time;
    const previousShape = time – 1/12;
    while (Math.floor(currentShape) === Math.floor(previousShape)) {
    seedRandom(random());
    random(min, max);
    }

  • Dan Ebberts

    May 22, 2022 at 10:08 pm

    See if this is close:

    f = timeToFrames(time);

    seedRandom(index,true);

    numShapes = 5;

    numVars = 4;

    varDur = 6;

    shapeDur = numVars*varDur;

    fCur = 0;

    segDur = 2;

    curShape = Math.floor(random(numShapes));

    for (fCur = 0; fCur <= f; fCur += segDur){

    curShape = (curShape + Math.floor(random(1,numShapes)))%numShapes;

    }

    seedRandom(fCur,true);

    curVar = Math.floor(random(numVars));

    framesToTime(curShape*shapeDur + curVar*varDur);

  • Marvin Claußen

    May 23, 2022 at 2:27 am

    It works perfectly, thank you so much Dan.

Viewing 1 - 3 of 3 posts

Log in to reply.

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