跳转到内容

Modulate

使用模运算函数输出数字的重复序列。

Common Attributes +

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 Offset1 将得到 1, 2, 0, 1, 2, 0

Offset - 偏移起始值。例如,如果模式是 0, 1, 2, 0, 1, 2…,Offset2 将得到 2, 3, 4, 2, 3, 4

Pass Value - 当余数 0 时,输出此值。

Fail Value - 当余数 不为 0 时,输出此值。

Custom Pattern - 输入由逗号分隔的值模式。

  1. 创建 3 个 Basic Shapes(circle, rectangle, polygon)。
  2. 选中所有 3 个 Shapes,单击 Shelf 中的 Duplicator icon。
  3. 在 Duplicator 上将 Count 设置为 x = 5y = 5
  4. 创建一个 Modulate
  5. Divisor 设置为 3
  6. 连接 modulate.id→duplicator.shapeId。

Divisor 为 3 时,Modulate 输出值为 0, 1, 2, 0, 1, 2, 0…,因此 Duplicator 输出 circle, rectangle, polygon, circle, rectangle, polygon, circle…(取决于添加的顺序)。

  1. 创建一个 Basic Shape
  2. 选中该 Shape,单击 Shelf 中的 Duplicator icon。
  3. 在 Duplicator 上将 Distribution 设置为 Linear
  4. Count 设置为 9Size 设置为 900
  5. 创建一个 Color Array
  6. 添加第二个索引并设置不同的颜色。
  7. 连接 colorArray.id→basicShape.FillColor。
  8. 创建一个 Modulate Behaviour。
  9. Mode 设置为 Pass/Fail
  10. Divisor 设置为 3
  11. 连接 modulate.id→colorArray.index。

生成的序列是 0,1,1,0,1,1,0…(数学推导见下文)。如果 Pass Value = 0Fail Value = 1,则转换为 pass, fail, fail, pass, fail, fail, pass…。如果 Color Array 上的颜色是红色和绿色,则生成的颜色序列将是 red, green, green, red, green, green, red, green

RemainderPass/Fail 模式使用 Modular Math

这里我们使用 Divisor3 来除一个 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,…,需要 Divisor4