Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expression: As Value Increases, Loop from 0 to 100

  • Expression: As Value Increases, Loop from 0 to 100

    Posted by Austin Hill on October 13, 2020 at 11:56 pm

    Is there an expression that can loop from 0 to 100 (or any arbitrary value) as a slider value increases indefinitely? For example, as the slider increases from 0 to 100, the expression outputs 0 to 100. Then when the slider increases from 100 to 200, the expression outputs 0 to 100 again. A slider value of 1328 would output 28, for example, and a slider value of 8568 would result in 68.

    I’ve searched around for this type of functionality but haven’t been able to find anything along these lines.

    I can make something loop twice using if/else statements, but if I want three repetitions (or four, etc.), I’d have to enter new variables and another tree to the if/else statement for each repetition I’d want. Heres is an expression repeating twice:

    input=thisComp.layer("Null 2").effect("Slider Control")("Slider");
    il1=0;
    ih1=50;
    ol1=116.5;
    oh1=-1883.4;
    il2=50;
    ih2=100;
    ol2=116.5;
    oh2=-1883.4;
    if(input<50){
    linear(input,il1,ih1,ol1,oh1);
    }else{
    linear(input,il2,ih2,ol2,oh2);
    }

    I’m attempting to make an odometer style counter and have the digits from 0-9 vertically in a text layer. I’m adjusting the vertical position of these layers as the slider increases. I’m using the linear function above to remap the slider to the relevant vertical positions I need for the text layers. Unfortunately, this doesn’t scale to X number of repetitions, only 2.

    Is there a way to loop a set of values as a slider value indefinitely increases?

    Thank you for reading!

    Walter Soyka replied 5 years, 10 months ago 2 Members · 3 Replies
  • 3 Replies
  • Walter Soyka

    October 14, 2020 at 12:08 am

    Use the modulo operator (%). This throws away the quotient and returns the remainder after integer division.

    For example, 27 % 10 = 7. More to your point, 1328 % 100 = 28.

  • Austin Hill

    October 14, 2020 at 1:13 am

    Thank you, Walter!!! That’s exactly what I was looking for. You’ve saved me countless hours.

    In case it helps someone else, using the modulo operator, I was able to rewrite the expression as follows:

    input=(thisComp.layer("Null 2").effect("Slider Control")("Slider")/10000)%100;
    il=0;
    ih=100;
    ol=116.5;
    oh=-1883.4;
    linear(input,il,ih,ol,oh);

    I have a slider keyframed from 0 to 100,000. This expression is for the hundred thousands place (100,000) as you can see in the first line (bolded above) the slider is divided by 10,000. For the ten thousands place (100,000), it is divided by 1,000 and so on until the ones place (100,000) which is multiplied by ten instead. The tens place (100,000) is neither multiplied nor divided. This works just like an odometer, each place must go through a full cycle for the place to the left to increment by one.

    I like this technique because, since the number columns are actually moving their position, you can use native motion blur. Plus, you can ease the slider to your liking for a quick count up and slow finish. Two things I was not able to do with other odometer techniques.

    I can use this for even hundred thousands, but the numbers will be misaligned at anything that’s not, like 145,938. Not a problem for this project but something to work on another day.

    Thanks again!! I really appreciate your help.

  • Walter Soyka

    October 14, 2020 at 2:33 am

    You’re welcome!

    I published an “advanced odometer” project a few years back that might also be helpful to you:

    https://f1.creativecow.net/file.php?id=5194&folder=advanced-odometer

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