ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression to return last value when Checkbox is enabled

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jacob Roth
Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 1:01:18 pm

Hi everybody,

So I'm trying to combine solutions from Dan Ebberts and it's not working so far.

I have the falling leaf effect that Dan wrote here:

http://www.aenhancers.com/viewtopic.php?t=8

And I'm trying to combine it with his code to return the last expression value at time here:

https://forums.creativecow.net/thread/227/34463

It's not really working, and I don't know how to fix it. The code I've attached is on position.

Any ideas?

yVelocity = 200; //pixels per second
oscFreq = thisComp.layer("Null 1")("Effects")("Oscillation Frequency")("Slider"); //oscillations per second
oscDepth = 35; //oscillation depth (pixels)
drift = 25; // drift (wind?) (pixels per second: - = left, + = right)
chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
n = 0;

if (chkBx.numKeys > 0){
n = chkBx.nearestKey(time).index;
if (chkBx.key(n).time > time) n--;
}
t = 0;
curTime = time;
if (n > 0){
for (i = n; i > 0; i--){
if (chkBx.key(i).value > 0){
t += (curTime - chkBx.key(i).time);
}
curTime = chkBx.key(i).time;
}
if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
}else{

value + [oscDepth*Math.sin(oscFreq*Math.PI*2*time) + drift *time,
yVelocity*time,0]
}


Return to posts index

Dan Ebberts
Re: Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 1:19:22 pm

I think what you need to do is replace time in falling leaf expression with the t variable calculated in the checkbox expression, like this:


yVelocity = 200; //pixels per second
oscFreq = thisComp.layer("Null 1")("Effects")("Oscillation Frequency")("Slider"); //oscillations per second
oscDepth = 35; //oscillation depth (pixels)
drift = 25; // drift (wind?) (pixels per second: - = left, + = right)
chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
n = 0;

if (chkBx.numKeys > 0){
n = chkBx.nearestKey(time).index;
if (chkBx.key(n).time > time) n--;
}
t = 0;
curTime = time;
if (n > 0){
for (i = n; i > 0; i--){
if (chkBx.key(i).value > 0){
t += (curTime - chkBx.key(i).time);
}
curTime = chkBx.key(i).time;
}
if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
}else{
if (chkBx.value > 0) t = time;
}

value + [oscDepth*Math.sin(oscFreq*Math.PI*2*t) + drift*t,
yVelocity*t,0]



Dan



Return to posts index

Jacob Roth
Re: Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 1:34:17 pm

Yep, that did it.

How translatable is the checkbox control for pausing an expression to other types of expressions. Like, if I want to be able to pause a wiggle?


Return to posts index


Dan Ebberts
Re: Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 3:32:39 pm

You would just need to use t for wiggle's 5th parameter (time):


chkBx = thisComp.layer("Null 1")("Effects")("Stop")("Checkbox");
n = 0;

if (chkBx.numKeys > 0){
n = chkBx.nearestKey(time).index;
if (chkBx.key(n).time > time) n--;
}
t = 0;
curTime = time;
if (n > 0){
for (i = n; i > 0; i--){
if (chkBx.key(i).value > 0){
t += (curTime - chkBx.key(i).time);
}
curTime = chkBx.key(i).time;
}
if ((curTime > 0) && (chkBx.key(1).value > 0)) t += curTime;
}else{
if (chkBx.value > 0) t = time;
}

wiggle(1,100,1,.5,t)



Dan



Return to posts index

Jacob Roth
Re: Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 5:46:58 pm

Dan you're blowing my mind. I didn't even know there were third and fourth parameters to the wiggle expression. What do they control?


Return to posts index

Dan Ebberts
Re: Expression to return last value when Checkbox is enabled
on Jun 21, 2018 at 6:13:07 pm

They control number of octaves and the influence of each octave in the noise wave, allowing you to make the wiggle more frenetic. I don't think I've ever used them, except to get to the time parameter.

Dan



Return to posts index


Jayden Bradley
Re: Expression to return last value when Checkbox is enabled
on Aug 15, 2018 at 3:39:08 pm

Hey, guys. Helpful information so far, however, i would like some help as to how to translate this time/t for other expressions. For e.g overshoot by Dan.

freq = 2;
decay = 5;
delay = .15;
dur = .12;

myDelay = (textIndex-1)*delay;
t = time - (inPoint + myDelay);
startVal = 100;
endVal = 0;

if(t &lt; dur){
linear(t,0,dur,startVal,endVal);
}else{
amp = (endVal - startVal)/dur;
w = freq*Math.PI*2;
endVal + amp*(Math.sin(t*w)/Math.exp(decay*t)/w);
}


Return to posts index

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