Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Help with Math.sin & blinking…

  • Help with Math.sin & blinking…

    Posted by Stephen Reber on July 27, 2009 at 2:25 am

    Hey all, I need a little help.

    I am trying to create a little more complex version of a blinking object using Math.sin…

    sec = 2; // duration of blink in seconds
    wave = Math.sin(time * Math.PI / sec);

    if (wave >= 0) 1 else 0;

    What I want to do is when the object blinks on, it stays on for “X” amount of time, and when it blinks off, it stays off for “X” amount of time

    What I did was create 2 sliders, one for the “off” time and one for the “on” time, along with a simple switch, so when the wave hits 0, “sec” is replace with the “off time” amount, and when the wave is at 1, “sec” is replaced with the “on time” amount (expression not shown).

    It obviously didn’t work, I understand why it didn’t work, but I don’t think I could properly explain it.

    Any thoughts on how I could make my idea work??

    Thanks in advance…

    Stephen =]

    Stephen Reber replied 17 years ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 27, 2009 at 3:12 am

    Something like this:

    offTime = effect(“On Time”)(“Slider”);
    onTime = effect(“Off Time”)(“Slider”);
    t = time % (offTime + onTime);
    if (t > onTime) 0 else 1

    Dan

  • Stephen Reber

    July 27, 2009 at 11:20 pm

    Dan…

    Thanks again for the help… totally brilliant! The original set up I had for my idea was a little insane.

    The one problem I am having is with modulus.

    time on and off = 5 and the time is 5, % = 0 (5%5)
    5 divided by 5 with a remainder of 0 or %0

    time on and off = 5 and the time is 7, % = 2 (7%5)
    7 divided by 5 with a remainder of 2 or %2

    O.K., but my problem is with…

    time on and off = 5 and the time is 2, % = 2?? (2%5)
    2 divided by 5 = .4 with no remainder, so % would be 0 right? But % comes out to 2.

    How do you figure modulus with x%y when x is smaller than y??

    Thanks again…

    Stephen =]

  • Dan Ebberts

    July 27, 2009 at 11:31 pm

    For x%y, if x is less than y, the remainder is x.

    For your 2%5 example, 2 divided by 5 is 0 with 2 remainder.

    Dan

  • Stephen Reber

    July 28, 2009 at 12:08 am

    Excellent! Thanks again Dan =]

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