Looking to create a standing wave, specifically a third harmonic–using expressions

New Here ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

Hello! I'm trying to write an expression that will animate a series of shapes moving up and down in a standing wave. (Like this https://en.wikipedia.org/wiki/Standing_wave).

 

Been digging through MotionScript.com for help with this, but haven't found anything that's giving me the right result.

 

TOPICS
Expressions , How to , Resources , Scripting

Views

86

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

If you own iExpressions, you could create a shape path with the desired animation using the Sine Wave iExpression.

[video]

 

If you want to attach objects to the path, you can first convert the expression into keyframes and then connect null layers to the vertices of the path using the "create nulls from path" script that is included in After Effects.

 

However, if you don't need a path at all, and only want to oscillate some layers up an down, then you could probably also write an expression along those lines:
[value[0],value[1]+Math.sin(time*multiplier)*amplitude]

 

This expression should make the layer oscilate up/down from its current position where "multiplier" controls the speed and "amplitude" defines how much it moves up and down.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

PS: go create the standing wave with the iExpression, you need to

- set its "speed" parameter to 0

- link the "wave height" parameter to a slider and keyframe it (or animate it with the sin expression from my previous post).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

If you click in the comp window with the pen tool and then add this path expression it might get you headed in the right direction:

freq = .5;
amp = 100;
t = time - inPoint;
a = amp*Math.sin(t*freq*Math.PI*2);
w = 500; // width
cycles = 3;
cycleW = w/cycles;

p = [[-w/2,0]]; // points
iT = [[0,0]]; // in tangents
oT = [[0,0]]; // out tangents
for (i = 0; i < cycles*2; i++){
  n = Math.floor(i/2)
  if (i%2){
    p.push([-w/2 + cycleW*n + 3*cycleW/4,-a]);
  }else{
    p.push([-w/2 + cycleW*n + cycleW/4,a]);
  }
  iT.push([-.1821*cycleW,0]);
  oT.push([.1821*cycleW,0]);
}
p.push([w/2,0]);
iT.push([0,0]);
oT.push([0,0]);
createPath(p,iT,oT,false);

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

LATEST

This version is a little better, it will put the standing wave where you click the pen tool:

 

freq = .5;
amp = 100;
w = 500; // width
cycles = 3;

t = time - inPoint;
a = amp*Math.sin(t*freq*Math.PI*2);
cycleW = w/cycles;
p0 = points()[0];
p = [p0]; // points
iT = [[0,0]]; // in tangents
oT = [[0,0]]; // out tangents
for (i = 0; i < cycles*2; i++){
  n = Math.floor(i/2)
  if (i%2){
    p.push(p0+[cycleW*n + 3*cycleW/4,a]);
  }else{
    p.push(p0+[cycleW*n + cycleW/4,-a]);
  }
  iT.push([-.1821*cycleW,0]);
  oT.push([.1821*cycleW,0]);
}
p.push(p0+[w,0]);
iT.push([0,0]);
oT.push([0,0]);
createPath(p,iT,oT,false);

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines