Modulate
使用模运算函数输出数字的重复序列。
Mode:
- Remainder - 基于 Divisor 值创建序列。
- Pass/Fail - 基于余数是否为 0(pass)来创建序列(fail)。
- Custom Pattern - 创建自定义序列。
Divisor - 设置值 n 将创建从 0:n-1 的数字序列。例如,值 3 将创建 0,1,2,0,1,2,0… 的序列(见下文)。
Index Offset - 偏移模式的顺序。例如,如果模式是 0, 1, 2, 0, 1, 2…,Index Offset 为 1 将得到 1, 2, 0, 1, 2, 0…
Offset - 偏移起始值。例如,如果模式是 0, 1, 2, 0, 1, 2…,Offset 为 2 将得到 2, 3, 4, 2, 3, 4…
Pass Value - 当余数 为 0 时,输出此值。
Fail Value - 当余数 不为 0 时,输出此值。
Custom Pattern - 输入由逗号分隔的值模式。
- 创建 3 个 Basic Shapes(circle, rectangle, polygon)。
- 选中所有 3 个 Shapes,单击 Shelf 中的 Duplicator icon。
- 在 Duplicator 上将 Count 设置为 x = 5,y = 5。
- 创建一个 Modulate。
- 将 Divisor 设置为 3。
- 连接 modulate.id→duplicator.shapeId。
当 Divisor 为 3 时,Modulate 输出值为 0, 1, 2, 0, 1, 2, 0…,因此 Duplicator 输出 circle, rectangle, polygon, circle, rectangle, polygon, circle…(取决于添加的顺序)。
- 创建一个 Basic Shape。
- 选中该 Shape,单击 Shelf 中的 Duplicator icon。
- 在 Duplicator 上将 Distribution 设置为 Linear。
- 将 Count 设置为 9,Size 设置为 900。
- 创建一个 Color Array。
- 添加第二个索引并设置不同的颜色。
- 连接 colorArray.id→basicShape.FillColor。
- 创建一个 Modulate Behaviour。
- 将 Mode 设置为 Pass/Fail。
- 将 Divisor 设置为 3。
- 连接 modulate.id→colorArray.index。
生成的序列是 0,1,1,0,1,1,0…(数学推导见下文)。如果 Pass Value = 0,Fail Value = 1,则转换为 pass, fail, fail, pass, fail, fail, pass…。如果 Color Array 上的颜色是红色和绿色,则生成的颜色序列将是 red, green, green, red, green, green, red, green…
Remainder 和 Pass/Fail 模式使用 Modular Math。
这里我们使用 Divisor 为 3 来除一个 number。观察当 number 每次递增 1 时,remainder 值的变化。
- 0÷3=00 \div 3 = 00÷3=0 remainder 0
- 1÷3=01 \div 3 = 01÷3=0 remainder 1
- 2÷3=02 \div 3 = 02÷3=0 remainder 2
- 3÷3=13 \div 3 = 13÷3=1 remainder 0
- 4÷3=14 \div 3 = 14÷3=1 remainder 1
- 5÷3=15 \div 3 = 15÷3=1 remainder 2
- 6÷3=26 \div 3 = 26÷3=2 remainder 0
- …
余数从 0 开始,每次增加 1,直到 number 达到比 Divisor 小 1 的值。之后序列重复。因此,要创建序列 0,1,2,3,0,1,2,3,…,需要 Divisor 为 4。