Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Convert increasing variable to looping variable

  • Convert increasing variable to looping variable

    Posted by Mike Foran on January 11, 2019 at 7:14 pm

    I’m trying to write an expression that converts a constantly increasing variable, like time, to a looping variable. Kind of like the ‘linear’ function but instead of clamping the value translation to either end of the range, it would loop the variable back around to the beginning again. I’ve written this looping expression, but it doesn’t really allow me to set the range of output values, it just cycles the variable every 10 seconds from 0 to 10. I also feel like there’s a better way to do this that I am not aware of.

    t = time;
    t = time;
    v = t;
    i = 0;
    End = 10
    if (t>End){
    i = Math.floor(t/End);
    v = t - (i*End);
    }

    [v];

    Jeff Kay replied 7 years, 4 months ago 3 Members · 3 Replies
  • 3 Replies
  • Walter Soyka

    January 11, 2019 at 7:22 pm

    Use the modulus operator — it returns the division remainder:

    time % 10

    Walter Soyka
    Designer & Mad Scientist at Keen Live [link]
    Motion Graphics, Widescreen Events, Presentation Design, and Consulting
    @keenlive   |   RenderBreak [blog]   |   Profile [LinkedIn]

  • Mike Foran

    January 11, 2019 at 8:03 pm

    Exactly! I knew there had to be a simpler method than what I was doing. Thank you.

  • Jeff Kay

    January 11, 2019 at 10:11 pm

    The one I’ve been using is
    Math.floor(time*Y)%X

    Where it increments Y times a second and counts from 0 to X-1.

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