Modulo in Motion

March 12, 2026

Modulo is one of those bits of maths that shows up everywhere in motion design.

If you work with expressions, utilities, duplicators, or procedural rigs, you keep running into it. Usually anywhere something needs to loop, repeat, wrap, or offset cleanly.

That is why it is worth understanding properly.

I came back to it after watching a tutorial from Studio Nordest the other day. It reminded me that although I've used modulo in After Effects expressions and Cavalry math utilities, I never felt I had a clean, teachable understanding of it.

So this is an attempt to make that understanding clear, first for myself, and hopefully for other motion designers too.

The goal here is not abstract maths for its own sake. It is to understand modulo as a practical motion design tool.

Definition of Modulo

In simple terms, modulo gives you the remainder after division.

The symbol for modulo is %. In this context it does not mean percent. It means "give me the remainder."

7 % 3 = 1
because 7 divided by 3 = 2 with remainder of 1

That sounds dry, but it is the reason values can wrap, repeat, and loop cleanly in motion systems.

The Core Idea

If you see something like time % 200 in an expression or calculation, the important thing to understand is this:

time is not looping.

time keeps increasing forever. Modulo takes that ever-increasing number and squashes it back into a smaller range.

So instead of getting 201, 202, 203, you get 1, 2, 3 again.

That is the cleanest way to think about it.

time % 200 means:

"Give me the position of time inside a 200-step cycle."

So the output goes like this:

0 % 200   = 0
1 % 200   = 1
2 % 200   = 2
...
199 % 200 = 199
200 % 200 = 0
201 % 200 = 1
202 % 200 = 2

Why It Resets

Because modulo gives you the remainder, not the decimal result of division.

For any number smaller than 200, 200 fits into it zero times, so the remainder is just the number itself.

  • 50 % 200 = 50
  • 127 % 200 = 127
  • 199 % 200 = 199

Then at 200, it resets:

  • 200 % 200 = 0
  • 201 % 200 = 1

So modulo gives you a wrapped value:

0 -> 1 -> 2 -> ... -> 199 -> 0 -> 1 -> 2

Why Modulo Is Useful in Motion

Modulo takes a value that keeps increasing, like time, and turns it into a repeating cycle you can use to drive animation.

In Cavalry, that usually means one of three things:

  • looping a value over time
  • creating a wave across duplicated shapes
  • offsetting behaviour by index so a pattern repeats cleanly

If you have a row of rectangles and you use time % 200 somewhere in the scaling logic, you are essentially feeding the system a value that keeps sweeping from 0 to 199, then jumping back to 0.

That reset is the repeat.

So the visual result is often not "everything scaling forever." It is more like a pulse, wave, or travelling pattern that reaches the end of its range and starts again.

Another Mental Model: Rotation

Another good mental model is rotation.

Imagine a value rotating forever.

If you use % 360, you are saying:

"Only give me the current angle inside one full turn."

So:

  • 10 % 360 = 10
  • 180 % 360 = 180
  • 359 % 360 = 359
  • 360 % 360 = 0
  • 361 % 360 = 1

The rotation itself keeps going.

But modulo gives you the current position inside a single 360-degree loop.

Conclusion

Modulo is division with the answer thrown away. All you keep is the remainder.

Because of that, any value that keeps growing forever can be made to cycle. It counts up, hits the limit, and starts again from zero.

That is what makes it so useful in animation. You are not creating a loop in the traditional sense. You are taking a value that never stops, and wrapping it inside a range that repeats.

If you want to repeat every 200 frames, just do time % numberOfFrames and your output will be that looping value.