Skip to main content
Participant
March 31, 2023
Answered

Set a minimum and maximum for rotation expression

  • March 31, 2023
  • 2 replies
  • 1675 views

Need to modify the attached code to include a minimum and maximum rotation in the wiggle expression. Say for example the VU meter needle will never rotate less than 2 and more than 100.

 

//Smooth wiggle

freq = effect("Speed")("Slider");

amp = effect("Range")("Slider");

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)

This topic has been closed for replies.
Correct answer Rick Gerard

You could tie rotation to opacity for your red light layer. Something like this:

r = thisComp.layer("VU Dial");
if (r > 90)
    100
else
    0

2 replies

Rick GerardCommunity ExpertCorrect answer
Community Expert
April 1, 2023

You could tie rotation to opacity for your red light layer. Something like this:

r = thisComp.layer("VU Dial");
if (r > 90)
    100
else
    0
Community Expert
March 31, 2023

That expression creates the changing values based on keyframes and slider values. You have several options. One of them would be to define the output wiggle value as "t" and then use a linear interpolation method to limit the output from 2 to 100. You would have to know what the minimum and maximum values that wiggle would generate, and those values are based on keyframes and sliders.

 

A linear interpolation looks like this:

t = wiggle(freq, amp, octaves = 1, amp_mult = .5, t = time);
r = linear(t, tMin, tMax, 2, 100)

 Without setting a bunch of keyframes and adding some sliders, I have no idea what tMin or tMax would be.

 

If you just want a random rotation wiggle from 2 to 100 that happens 8 times a second, all you need in the rotation property is:

t = wiggle(8, 100);
linear(t, -100, 100, 2, 100)
Participant
March 31, 2023

Thanks Rick, the liner expression did the trick. BTW if I want a peak LED indicator to light only when my expression reaches a certian amplitude how would I address this across layers?