FORUMS: list search recent posts

Convert increasing variable to looping variable

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Mike Foran
Convert increasing variable to looping variable
on Jan 11, 2019 at 7:14:55 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];


Return to posts index

Walter Soyka
Re: Convert increasing variable to looping variable
on Jan 11, 2019 at 7:22:17 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 [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Mike Foran
Re: Convert increasing variable to looping variable
on Jan 11, 2019 at 8:03:29 pm

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


Return to posts index


Jeff Kay
Re: Convert increasing variable to looping variable
on Jan 11, 2019 at 10:11:01 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.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]