How do we create a grid where every rectangle has a different color and rotation? In other words, how do we create variation for each single input shape? For this, we need copy stamping.
Copy stamping changes nodes in the network before the copy stamp node. That means that the NodeBox engine goes back and changes the outputs of input nodes every time it loops through the network.
When copy stamping is turned on, the nodes marked in red are re-evaluated for each copy.
For people used to programming: nodes such as copy and place work as a loop. Copy stamping gives you variables that input nodes can use as arguments for their parameters.
Let’s build the example above.
- Create a Rect node. Set Width to 10.00 and Height to 10.00.
- Create a Transform node. Set Rotation to 45.00.
- Connect rect1 to transform1.
- Create a Grid node. Set Width to 500.00 and Height to 150.00. Set Rows to 12 and Columns to 40.
- Create a Place node.
- Connect transform1 to place1 (shape).
- Connect grid1 to place1 (template).
We’ve now created the first step in our example: a lot of rectangles, all with the same color and rotation. Let’s use copy stamping to create variation.
To use copy stamping:
- Turn on copy stamping in the copy / place node.
- Use the stamp expression in the parameter we want to change.
The trick with copy stamping is to ask yourself: what do I want to change for every step? In our case, the rotation of every shape needs to be different. We can change the rotation by modifying transform1’s rotate parameter: that’s the parameter that needs copy stamping.
- In place1, turn Copy Stamping on.
- In transform1, set Rotate to the expression
Voila! Every rectangle now has a different rotation.
By turning copy stamping on, NodeBox revisits every node that’s connected to the shape port: if the node uses a stamp expression, NodeBox recalculates the node with the new value in place.
The stamp expression is the key to use copy stamping. Let’s examine it in detail:
The expression consists of two parts:
- The variable name (“CNUM”): We can create custom variables (the expression parameter in the place node) or use the built-in CNUM that NodeBox provides for us.
- The default value (45): If copy stamping is turned off, or if we’re just rendering the translate1 node, we don’t have access to the CNUM variable. In that case, we need a default value. As a rule, use the value that was there before. In our case, the rotate parameter was set to 45, so we’ll use the number 45 here as well.
CNUM is the copy number. For every copy we make, NodeBox assigns a unique index number that we can refer to:
- For the first copy, CNUM will be 0. (NodeBox starts counting at zero)
- For the second copy, CNUM will be 1.
- For the third copy, CNUM will be 2, and so on.
In our example, we’ll link the rotation to CNUM so the value of the rotate parameter changes for every copy:
- For the first copy, the rotation is 0.
- For the second copy, the rotation is 1.
- For the third copy, the rotation is 2.
Copy stamping can be used anywhere, but colors require a special mention since they require nested expressions.
- In rect1, set Fill to the expression
hsb(stamp("CPOS", 0), 1, 1)
- Instant rainbow!
The hsb function provides using hue, saturation and brightness. The saturation and brightness are set to 1. For the hue, we’ve used a stamp expression:
We use the copy position. This provides a relative value between 0.0 and 1.0 for every copy: The first copy will be 0.0, the last copy will be 1.0. If we have three copies, CPOS would be 0.0, 0.5, and 0.1. The 0.0 - 1.0 range is exactly what we need for colors.
We can use the stamp expression in any part of the hsb expression:
- In rect1, set Fill to the expression
hsb(1, stamp("CPOS", 1), 1)
- Set the Document Background to Red = 50, Green = 0, Blue = 75
We now used copy stamping to change the saturation of each copy.
Note that the rotation begins at zero in the top left and moves to the right, then to the next row, and so on. This order is defined by the point order of the template node. You can see this point order by double-clicking grid1 and turning on Point Numbers in the viewer.
We can use the sort node to change the ordering of the point numbers, creating interesting effects:
- If you have point numbers turned on, turn it off again.
- Double-click place1 to make it the rendered node.
- To make the effect more pronounced, we’ll move the rectangles off-center. In rect1 set Y to 5.00.
- Create a new Sort node. Set Scope to Points within geometry.
- Connect grid1 to sort1.
- Connect sort1 to place1 (template).
- In sort1 set Order to Proximity To Point. Note that the points start rotating from the center.
- Drag the handle to change the center of the sorting.
- Play around with the different order options. (such as Shift, Angle To Point, etc.)
The geometry page has more details on point numbers and their implications.
To create the initial example:
- In sort1 set Order to Random.
- In rect1 set Y back to 0.00.