Skip to main content
Participant
April 19, 2022
Question

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

  • April 19, 2022
  • 2 replies
  • 575 views

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.

 

This topic has been closed for replies.

2 replies

Dan Ebberts
Community Expert
Community Expert
April 19, 2022

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);
Dan Ebberts
Community Expert
Community Expert
April 19, 2022

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);

 

Mathias Moehl
Community Expert
Community Expert
April 19, 2022

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

 

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.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Mathias Moehl
Community Expert
Community Expert
April 19, 2022

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).

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects