ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

How to turn off and on an expression randomly

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Daniel Walker
How to turn off and on an expression randomly
on Jul 28, 2017 at 9:42:27 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] ;


Return to posts index

Andrei Popa
Re: How to turn off and on an expression randomly
on Jul 31, 2017 at 11:01:41 am

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

Andrei


Return to posts index

Daniel Walker
Re: How to turn off and on an expression randomly
on Jul 31, 2017 at 3:24:32 pm

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


Return to posts index


Andrei Popa
Re: How to turn off and on an expression randomly
on Aug 8, 2017 at 12:46:52 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


Return to posts index

Daniel Walker
Re: How to turn off and on an expression randomly
on Aug 15, 2017 at 2:40:12 am

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


Return to posts index

Daniel Walker
Re: How to turn off and on an expression randomly
on Aug 15, 2017 at 3:15:12 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.


Return to posts index


Daniel Walker
Re: How to turn off and on an expression randomly
on Aug 15, 2017 at 3:31:58 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;


Return to posts index

Daniel Walker
Re: How to turn off and on an expression randomly
on Aug 15, 2017 at 4:27:46 pm

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


Return to posts index

Andrei Popa
Re: How to turn off and on an expression randomly
on Aug 16, 2017 at 7:28:41 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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]