跳到內容

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