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。