Modulate
Intro
Output repeating sequences of numbers using the modulus function.
UI
Mode:
- Remainder - Create a sequence based on a Divisor value.
- Pass /Fail - Create a sequence based on whether the remainder is 0 (pass) or not (fail).
- Custom Pattern - Create a custom sequence.
Divisor - Setting a value of n will create a sequence of numbers from 0:n-1. e.g. a value of 3 will create a sequence of 0,1,2,0,1,2,0... (see below).
Index Offset - Offset the order of the pattern. e.g. if the pattern is 0, 1, 2, 0, 1, 2... an Index Offset of 1 will result in 1, 2, 0, 1, 2, 0...
Offset - Offset the start value. e.g. if the pattern is 0, 1, 2, 0, 1, 2... an Offset of 2 will result in 2, 3, 4, 2, 3, 4...
Pass Value - When the remainder is 0, output this value.
Fail Value - When the remainder is not 0, output this value.
Custom Pattern - Enter a pattern of values separated by commas.
- Create 3 Basic Shapes (circle, rectangle, polygon).
- With all 3 Shapes selected, click the Duplicator icon in the Shelf.
- Set Count to x = 5, y = 5 on the Duplicator.
- Create a Modulate.
- Set Divisor to 3.
- Connect modulate.id→duplicator.shapeId.
With a Divisor of 3 Modulate is outputting values of 0, 1, 2, 0, 1, 2, 0... so the Duplicator outputs circle, rectangle, polygon, circle, rectangle, polygon, circle... (depending on the order they were added).
- Create a Basic Shape.
- With the Shape selected, click the Duplicator icon in the Shelf.
- Set the Distribution to Linear on the Duplicator.
- Set Count to 9 and Size to 900.
- Create a Color Array.
- Add a second index and set a different color.
- Connect colorArray.id→basicShape.FillColor.
- Create a Modulate Behaviour.
- Set Mode to Pass/ Fail.
- Set Divisor to 3.
- Connect modulate.id→colorArray.index.
The resulting sequence is 0,1,1,0,1,1,0... (see below for the math). If the Pass Value = 0 and Fail Value = 1 then that translates to pass, fail, fail, pass, fail, fail, pass... If the colors on the Color Array are red and green the resulting sequence of colors will then be red, green, green, red, green, green, red, green...
The Remainder and Pass/ Fail modes use Modular Math.
Here we're dividing a number using a Divisor of 3. Observe what happens to the remainder value as the number increments by one.
- remainder 0
- remainder 1
- remainder 2
- remainder 0
- remainder 1
- remainder 2
- remainder 0
- ...
The remainders start at 0 and increase by 1 each time until the number reaches one less than the Divisor. After that, the sequence repeats. So to create the sequence 0,1,2,3,0,1,2,3,... a Divisor of 4 is required.