Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Variable frequency for a sinusoidal movement

  • Variable frequency for a sinusoidal movement

    Posted by Sam Beckett on September 19, 2016 at 8:01 pm

    Hi

    I would like to simulate the butterfly flight with its chaotic changes. For this I wrote the following code into the Y Rotation of the left wing (the right one behaves the exact opposite way).
    Freq_Min = thisComp.layer("Prarmètres généraux").effect("Freq_Min")("Curseur") ;
    Freq_Max = thisComp.layer("Prarmètres généraux").effect("Freq_Max")("Curseur") ;

    Freq_Offset = Freq_Min ;
    Freq_Delta = (Freq_Max - Freq_Min) / 2 ;

    Wiggle_Frequency = Freq_Offset + wiggle(1, Freq_Delta) + Freq_Delta ;

    //Wiggle_Frequency ;
    //Math.sin(10*time*2*Math.PI) ;
    Math.sin(Wiggle_Frequency*time*2*Math.PI) ;

    When I look the behaviour of this wing through the graphic view I notice that the frequency increases with time whereas I want the frequency to change along the wiggle value.

    1 – When I look at the graph of:Wiggle_Frequency
    the value oscilates randomly between 8.92 and 10.15
    whereas I expected it to oscilate randomly between 9 and 10

    2 – When I look at the graph ofMath.sin(10*time*2*Math.PI)
    The frequency (10Hz) doesn’t change all along the timeline, everything behaves as expected.

    3 – Now if we use this “Wiggle_Frequency” as a changing frequency:Math.sin(Wiggle_Frequency*time*2*Math.PI)
    The graph of this third value shows clearly a sinwave which frequency changes but also inexorably increases along time
    Whereas I expected this frequency not to increase more and more.

    Could someone please spot my mystakes?
    I try to find some examples either on creativecow or somewhereelse but I’ve not found any case like this.

    Edit: Here is a screenshot that shows more about this strange behaviour:

    in a sin function, when changing the frequency, the changing values are misinterprated by the script so the frequency “goes crazy” without any reason.

    Sam Beckett replied 9 years, 2 months ago 3 Members · 7 Replies
  • 7 Replies
  • Dan Ebberts

    September 19, 2016 at 8:27 pm

    It’s not a simple problem. This should help though:

    https://www.motionscript.com/articles/speed-control.html

    If you’re wiggling the frequency, you’ll probably need the frame-by-frame method.

    Dan

  • Sam Beckett

    September 19, 2016 at 8:45 pm

    Thanks a lot Dan, this si exactly what I needed.
    You couldn’t give me a better analysis.

    Do you have any clue why my initial wiggle that shouldn’t overpass the [9;10] interval does it anyway ? It looks like there is a kind of 10% overpassing but I don’t know why.

  • Dan Ebberts

    September 19, 2016 at 9:08 pm

    In my experience, wiggle() can give you an extra plus or minus 20% or so. You can either factor that in, or sometimes just changing the random seed will give you a more well-behaved wiggle.

    Dan

  • Sam Beckett

    September 19, 2016 at 10:18 pm

    Understood, thanks a lot for your so quick help.

    Now I am sorry but if I follow the document there isn’t any solution given for my precise case :
    Controlling the frequency with a wiggle expression.

    So I try to follow the principle with the following code :

    Freq_Min = 1 ;
    Freq_Max = 2 ;
    Freq_Offset = Freq_Min ;
    Freq_Delta = (Freq_Max - Freq_Min) / 2 ;

    freq = Freq_Offset + wiggle(0.1, Freq_Delta) + Freq_Delta ;
    amp = 100;
    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);
    }
    value + amp*Math.sin(accum*Math.PI*2)

    But the expression returns an error.
    As the wiggle into the “freq” variable breaks the rest of the code, I put the frequency wiggled into a Slider Control :
    Frequency Slider :
    Freq_Min = 1 ;
    Freq_Max = 2 ;

    Freq_Offset = Freq_Min ;
    Freq_Delta = (Freq_Max - Freq_Min) / 2 ;

    Freq_Offset + wiggle(0.1, Freq_Delta) + Freq_Delta ;

    Y Rotation parameter :
    freq = thisComp.layer("Prarmètres généraux").effect("Frequency")("Slider") ;

    amp = 100;
    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);
    }
    value + amp*Math.sin(accum*Math.PI*2)

    Now the program doesn’t contain any error but the graph behaves wrongly.
    So It turns that we have to work with an integrator expression, like your document explained but in my case we control the frequency of the sinwave by a wiggle expression. That is where I’m stuck.

  • Dan Ebberts

    September 20, 2016 at 12:50 am

    It would help to know the error message you’re getting with the first version.

    Dan

  • Kalleheikki Kannisto

    September 20, 2016 at 5:14 am

    You might consider wiggling the Time Remapping Effect for the wing animation. If you have the butterfly wing animation in a precomp it should speed up and slow down the wing motion only, not the overall motion of the butterfly.

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Sam Beckett

    February 23, 2017 at 1:31 pm

    Thank you very much, this may be very helpful to sort this out very easily.
    With all these responds I might close this thread as answered.

    Thank you all for your help.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy