rendering

A linear keyframe integrator is applied to wiggle() ‘s time attribute (rather than frequency attribute) to generate a smooth frequency ramp.

Control wiggle speed

When trying to control the speed (actually the frequency) of the Wiggle () function, you face exactly the same challenges as the previous examples in this article. The function has built-in frequency and amplitude parameters. Typically, you just set these parameters to the desired values and leave them unchanged. For example, you can set the rotation property to a simple 5 swings per second with an amplitude of 10, as follows:

freq = 5;
amp = 10; 
wiggle(freq,amp)
Copy the code

This will give you the oscillation waveform as shown below.

This is the oscillation waveform generated by the static frequency parameters

Sooner or later, though, you’ll give up the temptation to animate these parameters. It turns out that there is no problem with animating the amplitude parameters. However, frequency parameters are a familiar story with an unfortunate ending (AEJoy — Expression of Speed and Frequency Control (I) [JS]). By now, you’re probably not surprised that the method of binding frequency parameters directly to the slider has a fatal flaw:

freq = effect("Slider Control") ("Slider");
amp = 10; 
wiggle(freq,amp)
Copy the code

In the figure below, you can see the result. The keyframe ramp for the slider control (pink line) goes from 0 to 5, then stays at 5, then descends down the ramp back to 0. You would hope that the oscillating frequency would follow, but unfortunately you get the ugly results seen below.

Binding frequency parameters directly to the slider controls results in undesirable results

Your next instinct might be to apply our linear keyframe integral expression to the frequency parameter:

freq = effect("Slider Control") ("Slider");
amp = 10;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
  accum = freq.key(1).value*(freq.key(1).time - inPoint);
  for (i = 2; i <= n; i++){
    if (freq.key(i).time > time) break;
    k1 = freq.key(i-1);
    k2 = freq.key(i);
    accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
  }
  accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
  accum = freq.value*(time - inPoint);
}
wiggle(accum,amp)
Copy the code

The graph below shows this unfortunate result.

Applying a linear keyframe integrator to the frequency parameter yields this terrible result

Ah. Not even close! In fact, it’s even worse than previous attempts. It should be clear by now that we cannot animate the frequency parameters and hope for success. All is not lost, however. It turns out that we can apply the integrator expression to the seldom-used fifth wiggle() argument, time, to get the result we want. So:

freq = effect("Slider Control") ("Slider");
amp = 10;
n = freq.numKeys;
if (n > 0 && freq.key(1).time < time){
  accum = freq.key(1).value*(freq.key(1).time - inPoint);
  for (i = 2; i <= n; i++){
    if (freq.key(i).time > time) break;
    k1 = freq.key(i-1);
    k2 = freq.key(i);
    accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
  }
  accum += (freq.value + freq.key(i-1).value)*(time - freq.key(i-1).time)/2;
}else{
  accum = freq.value*(time - inPoint);
}
wiggle(1,amp,1.. 5,accum)
Copy the code

Now we have a beautiful slope of frequency from zero to five times per second, and then back to zero again. (If you want to know the third and fourth cryptic parameters of Wiggle (), see the references section of this article.)

The swing frequency can be animated by applying a linear keyframe integrator to time parameters

Its specific example effect can be seen from the above renderings.

The reason for this is that we use an integrator to calculate the total elapsed time based on the value of the frequency slider. We set the actual frequency parameter to oscillate once per second and remain constant. We use time parameters to move through time at a rate determined by the slider control.

Wiggle’s fourth parameter, the multiplier, determines how much of each multiplier is added to the resulting waveform. The default value of this parameter is 0.5, which means that each successive octave will have half the impact of the previous octave.