Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Finding the remainder of a division sum

  • Finding the remainder of a division sum

    Posted by Jim Lefevre on March 9, 2012 at 4:31 pm

    I’m needing to get the remainder of a division sum.

    I have a slider which has the values of 1 to 365 (DAYS_YEAR) and I need to cycle something that takes 29 days to cycle (MOON_PHASE) but using that DAYS_YEAR as its driver.

    I have figured out that if I divide my DAYS_YEAR driver by the MOON_PHASE

    (DAYS_YEAR)/(MOON_PHASE)

    I get a result which all I need is the ‘remainder figure’ (the underlined figure beneath)

    e.g.

    (DAYS_YEAR) / (MOON/PHASE) (MOON_ROT)
    ……….1…………………..29…………..=………….0.0344827586206897
    ……….28………………….29…………..=………….0.9655172413793103
    ……….29………………….29…………..=………….1 (doh!)
    ……….30………………….29…………..=………….1.03448275862069

    … the remainder that I take from that I use as a percentage to drive the MOON_PHASE rotation…

    If I can get that remainder figure then it would be

    360*MOON_ROT

    to give me the degrees it goes round

    I searched through the forums and have found one of the hallowed Mr Ebbert’s posts on the %

    https://forums.creativecow.net/readpost/227/7858

    but I’m struggling to make it all work.

    I has thought that I could use the % function but I’m getting rather bold single integers

    ((thisComp.layer(“DAYS_YEAR_DRIVER”).effect(“DAYS_YEAR”)(“Value/Offset/Random Max”))%thisComp.layer(“MOON_PHASE”).effect(“MOON_PHASE”)(“Slider”))

    Where
    DAYS_YEAR_DRIVER is a layer with the date as a single integer value
    and
    MOON_PHASE = 29

    as always, many thanks in advance for taking a look!!

    http://www.jimlefevre.com

    Jim Lefevre replied 14 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    March 9, 2012 at 6:12 pm

    The simplest way to get a remainder is probably the JavaScript modulo operator (%). You would use it like this:

    num = 0.0344827586206897;
    remainder = num%1;

    Dan

  • Jim Lefevre

    March 14, 2012 at 8:10 am

    Thank you! Yes, I’m there! And what’s more I think I understand!!

    As always, many many thanks Dan.

    http://www.jimlefevre.com

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