# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Swing Expression on Text

• # Swing Expression on Text

Posted by on December 1, 2023 at 1:42 am

Hey guys, I have a pretty simple question about swing expression.

So, I’m using this expression that I took from internet to make the swing animation on my text:

``````freq = 1.5;
decay = 0.8;
duration = 0.10;
r = textIndex*thisComp.frameDuration*0.7;
t = time - (inPoint + r);
startVal = [100,100,100];endVal = [0,0,0];
if (t < duration){
linear(t,0,duration,startVal,endVal);
}else{
amp = (endVal - startVal)/duration;
w = freq*Math.PI*2.5;
endVal + amp*(Math.sin((t-duration)*w)/Math.exp(decay*(t-duration))/w);}``````

But I want to animation my letters in random. And I turn on the Randomize Order under Range Selector, it doesn’t do a thing, so how do I go about it?

Here’s a screen recording where you can see everything.

I also attached an AEP project file.

3 Members · 8 Replies
• 8 Replies
• ### Dan Ebberts

December 1, 2023 at 5:34 pm

Play around with this:

`freq = 1.5;decay = 0.8;duration = 0.10;maxDelay = 1;seedRandom(textIndex,true);r = random(maxDelay);t = time - (inPoint + r);startVal = [100,100,100];endVal = [0,0,0];if (t < duration){  linear(t,0,duration,startVal,endVal);}else{  amp = (endVal - startVal)/duration;  w = freq*Math.PI*2.5;  endVal + amp*(Math.sin((t-duration)*w)/Math.exp(decay*(t-duration))/w);}`
• ### George Beridze

December 1, 2023 at 7:41 pm

Yes!!! Thank you so much, works like a charm! 🙂

May I ask you another question?

In the code that I posted, swing animation happens from first letter of the text, and I’m wondering how to go about making the animation to start from the last letter of the text?

• ### Dan Ebberts

December 1, 2023 at 8:03 pm

Try changing this line:

`r = textIndex*thisComp.frameDuration*0.7;`

to this:

`r = (textTotal - textIndex)*thisComp.frameDuration*0.7;`
• ### George Beridze

December 1, 2023 at 8:47 pm

You’re an absolute legend!

Thank you. x

• ### George Beridze

December 1, 2023 at 9:19 pm

Hey Dan, one last question..

I’ve been playing around with the seedRandom function and can’t get my head around on how to change the seed of the random. Meaning – how can I change the randomness of it?

• ### Dan Ebberts

December 1, 2023 at 9:38 pm

Replace this line:

`seedRandom(textIndex,true);`

with this:

`seed = 17;seedRandom(textIndex+seed,true);`

Then you just change the seed variable (or tie it to a slider, maybe) to change the randomness.

• ### George Beridze

December 1, 2023 at 9:53 pm

Bless you!

• ### Brie Clayton

December 2, 2023 at 11:45 pm

Thank you, Dan!

We use anonymous cookies to give you the best experience we can.