Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to turn off and on an expression randomly

  • How to turn off and on an expression randomly

    Posted by Daniel Walker on July 28, 2017 at 9:42 pm

    Hi there guys , I’m trying to make a 3d object to scale up and down to the beats of a music with this expression:

    and it is working good so far, I just need for the expression to to turn off and on randomly for a couple of seconds.
    Like 3s on and and 5s off. when is off it will stay at a regular size which is 100 and on it ill be scaling at the beats. I tried some random expression but the change is too jerky . Any help please . Thanks in advance.

    minAudio = 0;
    maxAudio = 100;
    minStretch = 100;
    maxStretch = 125;
    audioLev = thisComp.layer("Sound Key 2").effect("Sound Keys")("Output 1");
    s = linear(audioLev, minAudio, maxAudio, minStretch, maxStretch);
    [s,s,s] ;

    Andrei Popa replied 8 years, 9 months ago 2 Members · 8 Replies
  • 8 Replies
  • Andrei Popa

    July 31, 2017 at 11:01 am

    You could try to multiply the random expression with 3,4 so it is enabled/disabled 3,4 seconds.

    Andrei

  • Daniel Walker

    July 31, 2017 at 3:24 pm

    Hi Andrei thanks for the reply, could you show me how would it look. Thanks.

  • Andrei Popa

    August 8, 2017 at 12:46 pm

    Hey Daniel. I thought you had a random enable/disable expression and it was hapening too often. Wll, in case you don’t, something you can try is
    modulusSeven = Math.round(time%7);
    if(modulusSeven <= 3 ){
    //your expression here
    }
    else value;

    This will enable the expression for 3.5 seconds, and then disable it 3.5 and so on. I think you could play with the 7 and 3 numbers so you can get something that seems random.

    Andrei

  • Daniel Walker

    August 15, 2017 at 2:40 am

    Thank you so much for that, you are a magician. Thanks a million Andrei Popa .

  • Daniel Walker

    August 15, 2017 at 3:15 pm

    it is working good but the only thing now is that it is staying 3 sec withe effect on the scale expression and like a fraction on the normal state of the scale . How can i put a time or more duration for the normal state of the scale.

  • Daniel Walker

    August 15, 2017 at 3:31 pm

    Awesome !!! I added this at the end of value and that added more time to the initial state and it is working, I know there may be a better solution but so far i can go with this thanks a lot Andrei Popa

    modulusSeven = Math.round(time%7);
    if(modulusSeven &lt;= 5 )
    {
    minAudio = 0;
    maxAudio = 100;
    minStretch = 100;
    maxStretch = 125;
    audioLev = thisComp.layer("Sound Key 2").effect("Sound Keys")("Output 1");
    s = linear(audioLev, minAudio, maxAudio, minStretch, maxStretch);
    [s,s,s];
    //your expression here
    }
    else value + modulusSeven;

  • Daniel Walker

    August 15, 2017 at 4:27 pm

    Well still not working that Well, still too short the time , any Help with this guys?

  • Andrei Popa

    August 16, 2017 at 7:28 am

    You could add 2 “Slider Control” controls to this layer. Name them “Cycle duration” and “Expression duration”. The expression then for this would be:
    modValue = Math.floor(time%effect("Cycle duration")("Slider"));
    if(modValue < effect("Expression duration")("Slider") ){
    minAudio = 0;
    maxAudio = 100;
    minStretch = 100;
    maxStretch = 125;
    audioLev = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    s = linear(audioLev, minAudio, maxAudio, minStretch, maxStretch);
    [s,s,s];
    }
    else value;

    So the time that the layers stays still is “Cycle duration” minus “Expression duration”. Play with this 2 until you get something you like(Expression duration should always be smaller than Cycle duration). If, for example, you set them to be 15 and 9, the layer will scale up and down 9 seconds and then stay still until it reaches 15 seconds, and start moving again. If you add the modValue to the value at the end, you make the layer grow a bit each second.

    Andrei

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