Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions new random value every time

  • new random value every time

    Posted by Micheel Leavitt on July 26, 2009 at 7:14 am

    Hi, I have this code I tried, and I figured it wouldn’t work because its lacking, I just don’t know how to say what I want it to do properly.

    mus = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);
    seedRandom(2,true)
    random([0,0,0,1],[1,1,1,1])
    if(mus>10){
    seed = (random())
    seedRandom(seed,true)
    random([0,0,0,1],[1,1,1,1])
    }

    What I want it to do is create a new random “seed” value every time “mus” goes past 10. Is this a while loop or something else? I couldn’t think of anything so if anyone has an idea, any help is most appreciated. Thank You!

    Micheel Leavitt replied 16 years, 9 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 26, 2009 at 1:52 pm

    You need an audio level threshold detector, as described here:

    https://www.motionscript.com/design-guide/audio-trigger.html

    Just use “t” as your seed.

    Dan

  • Micheel Leavitt

    July 27, 2009 at 6:40 am

    Hehe, I tried to make sense of your code, but I’m lost. I changed the variable “t” to a random number and a random color array and I finally got AE to accept what I was trying to make, but it was a fail, it just gives one random color. Here is what I got:

    threshold = 10.0;

    audioLev = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);

    above = false;
    frame = Math.round(time / thisComp.frameDuration);
    while (true){
    t = random();//edited
    if (above){
    if (audioLev.valueAtTime(t) < threshold){ frame++; break; } }else if (audioLev.valueAtTime(t) >= threshold){
    above = true;
    }
    if (frame == 0){
    break;
    }
    frame–
    }
    if (! above){
    t = 0;
    }else{
    t = random();//edited
    }
    seedRandom(t,true)
    random([0,0,0,1],[1,1,1,1])//this final output when channel hits 10?

    I see it works perfectly the way it is for scaling, which totally rocks, but I’m at a loss since it seems pretty condensed, and I don’t really know programming too well. If you have an idea as to how to chop it up a bit to allow it to call colors, sweet, if it won’t work ah well, didn’t realize it would be that complex. Thanks for the help tho!

  • Dan Ebberts

    July 27, 2009 at 1:26 pm

    Sorry, I think I pointed you to the wrong example. Try this:

    threshold = 10.0;

    audioLev = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”);

    above = false;
    frame = Math.round(time / thisComp.frameDuration);
    n = 0;
    while (frame >= 0){
    t = frame * thisComp.frameDuration;
    if (above){
    if (audioLev.valueAtTime(t) < threshold){ above = false; } }else if (audioLev.valueAtTime(t) >= threshold){
    above = true;
    n++;
    }
    frame–
    }

    seedRandom(n,true)
    random([0,0,0,1],[1,1,1,1])

    Dan

  • Micheel Leavitt

    July 28, 2009 at 4:15 am

    Ah, guess I should have done a little more exploring, I would have found it. Thank you so much, this works astoundingly.

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