Modulus
3583 2 0-
- ferilous
- Member
- 27 posts
- Joined: March 2017
- Offline
-
- mestela
- Member
- 1828 posts
- Joined: May 2006
- Online
When you learned division in primary school you'd do remainders, eg
7 ÷ 3 = 2, remainder 1
5 ÷ 3 = 1, remainder 2
modulo is just the remainder part:
7%3=1
5%3=2
This is useful for setting up loops. Eg, if you calculate the remainder of dividing things by 4, counting from 1 to 10, you get this (swapping ÷ for / like you do in most computer languages) :
1/4=0, remainder 1
2/4=0, remainder 2
3/4=0, remainder 3
4/4=1, remainder 0
5/4=1, remainder 1
6/4=1, remainder 2
7/4=1, remainder 3
8/4=2, remainder 0
9/4=2, remainder 1
10/4=2, remainder 2
etc
Or used in a timing structure this works for floating point too, so you could do @Time%1, and the result is a timing counter that goes 0.0, 0.1, 0.2… 0.8, 0.9, 0.0, 0.1, 0.2 etc
In that example above its taking the current frame ($F), subtracting 1, then modulo by 17. The result is a set of numbers that constantly counts from 0 to 16, 0 to 16, 0 to 16… for the length of your timeline.
The minus 1 part there just determines what the first number is, so here it starts at 0 rather than 1 (assuming your framerange starts from 1).
-matt
7 ÷ 3 = 2, remainder 1
5 ÷ 3 = 1, remainder 2
modulo is just the remainder part:
7%3=1
5%3=2
This is useful for setting up loops. Eg, if you calculate the remainder of dividing things by 4, counting from 1 to 10, you get this (swapping ÷ for / like you do in most computer languages) :
1/4=0, remainder 1
2/4=0, remainder 2
3/4=0, remainder 3
4/4=1, remainder 0
5/4=1, remainder 1
6/4=1, remainder 2
7/4=1, remainder 3
8/4=2, remainder 0
9/4=2, remainder 1
10/4=2, remainder 2
etc
Or used in a timing structure this works for floating point too, so you could do @Time%1, and the result is a timing counter that goes 0.0, 0.1, 0.2… 0.8, 0.9, 0.0, 0.1, 0.2 etc
In that example above its taking the current frame ($F), subtracting 1, then modulo by 17. The result is a set of numbers that constantly counts from 0 to 16, 0 to 16, 0 to 16… for the length of your timeline.
The minus 1 part there just determines what the first number is, so here it starts at 0 rather than 1 (assuming your framerange starts from 1).
-matt
Edited by mestela - Oct. 8, 2017 19:35:51
-
- ferilous
- Member
- 27 posts
- Joined: March 2017
- Offline
-
- Quick Links