Activity › Forums › Adobe After Effects › expression increase number by X value
-
expression increase number by X value
Posted by Rafael on September 4, 2007 at 10:39 pmIs it possible to create a short expression that would range from 0-100 and define the increasing step? Let’s say every 12, so the result would be 12,24,36,48,…?
Ido Shor replied 9 years, 9 months ago 4 Members · 10 Replies -
10 Replies
-
Rutger
September 5, 2007 at 2:26 amRafael,
I am not exactly sure that I understand the question. I mean you want the result to be multiple discrete values in an array? or in time?
I am assuming that you want a propery (e.g. scale) to change from 0 to 100 at discrete steps in time. I am not sure if this is what you mean, but maybe this will give you some ideas.
Create a solid and apply the following expression to the scale value. If you change the step value, it changes the interval. Notice how the scale changes abruptly in time
totaltime = thisComp.duration;
step = 10;
counter = Math.floor(step*time/totaltime);
scaleval=100*(counter+1)/(step);
[scaleval,scaleval]Hopefully it helps, I think the Math.floor function is what you are looking for, since it will create “jumps” in time, rather than smooth transitions.
Rutger
-
Mike Clasby
September 5, 2007 at 4:38 amI totally agree with Rutger. What are you trying to do?
Here is an expression when put on Rotation that steps form 0 to 100 in increments of 12. The rotation on the layer was keyframed from 0 to 360 degrees, and the expression breaks the change into 12 degree increments, stopping at 100 (degrees).
step = 12;
r = rotation/step;
myR = Math.floor(r);
StepR = myR*step;
if (StepR > 100) 100 else StepRIt would really help if we knew what you wanted to do.
-
Rafael
September 5, 2007 at 3:07 pmawesome guys!
what I have been trying to do is to animate an equalizer. I have seen quite few tutorials on how to do it. The one I decide to go for is easy to modify when I’ll receive a new soundtrack (client to decide later which soundtrack). I am using the trapcode Sound Keys. I have a vertical bar made of 24 segments. As the sound peak to 100% the bar gets full. I have linked the bar with a ‘Linear wipe’ at 180 degrees. It’s good because it ranges from 0-100%, so I won’t have a sudden peak going over (though an expression could have limit the range, but I am not good with expression).
So I guess I could use one of your expression and try to modify with the Linear wipe ‘Transition Completion’? -
Mike Clasby
September 5, 2007 at 6:10 pmIf you did it with AE’s Convert Audio to Keyframes (it creates a new layer named “Audio Amplitude”), it would look like this expression (on “Transition Completion” of the effect Linear Wipe):
step = 4;
minAudio = 0;//minimum for Audio Amplitude to kick in
maxAudio = 25; //maximum for audio Amplitude
minValue = 0; //minimum value you want for Transition Completion
maxValue = 100; //maximum value you want for Transition Completionamount = thisComp.layer(“Audio Amplitude”).effect(“Both Channels”)(“Slider”)/step;
Math.floor(linear(amount,minAudio,maxAudio,minValue,maxValue))*step
If you did it with AE’s Convert Audio to Keyframes, it creates a new layer named “Audio Amplitude” (that is literally the total Loudness of the clip, not broken into frequencies like SoundKeys does), and the expression connects Transition Completion to that. You need to look at the graph of the Audio Keyframes and pickout the min and max audio keyframes and plug those in.
I don’t have soundkeys, but with the demo version it would look like this, on “Transition Completion”:
step = 4;
a = thisComp.layer(“Black Solid 1_soundkeys”).effect(“Sound Keys”)(“Output 1”)/step;
Math.floor(a)*stepThe layer I had soundkeys applier to was named “Black Solid 1_soundkeys”, so plug your layer name into there.
Since you said there were 24 segments, I used 4 pixels as the step.
-
Rafael
September 5, 2007 at 7:40 pmit’s almost working! But I think the problem is the percentage:
it increases correctly like you specify the value step = 4;
But it gives now percent like 23% 26% 29%… but that doesn’t match the ‘transition Completion’ to be where it should because percentage doesn’t match position increase.
I guess the formula for step should be something like:
100/24*4
?
I missed those days when I was good in mathematics..! -
Rutger
September 6, 2007 at 1:21 amRafael,
I tried the two versions that yikesmikes suggested and both work fine for me, I get values of 46,50,54,58 etc. so there must be a small error somewhere.
Also, I don’t understand what you mean by “but that doesn’t match the ‘transition Completion’ to be where it should because percentage doesn’t match position increase.”. In my opinion the expression that we are using defines the transition completion value so it should “match” by definition. Or do you mean that it does not match the Audio Amplitude?
Rutger
-
Mike Clasby
September 6, 2007 at 2:42 amYep, they work for me too. I make so many mistakes I have to test them before I publish.
-
Rafael
September 6, 2007 at 4:59 amit works too. But when the sound is off, the Linear Wipe value is 0% which translate to show the bar of the equalizer. It should gives 100% so the Linear wipe would be complete.
I did this, I add ‘101-‘ in the expression for the Sound Key, Range value:
101-effect(“Sound Keys 5”)(45)it seems to work fine now! Anyway big thanks to you guys for your help.
-
Ido Shor
July 31, 2016 at 1:03 pmis there a way for the change to be more smooth? and not on a “hold” base interpolation?
I am trying to do this step expression on a x position of a layer.
I.S
Reply to this Discussion! Login or Sign Up