Expressions allow you to link the value of one parameter to that of another. It creates a dependency onto other parameters, and will update the network accordingly when one of the dependent parameters change. If you know how to use formulas in Microsoft Excel, you know how expressions work.
This tutorial expects you have followed the basic tutorial already and know how to create nodes and connect them together.
Contents |
Connecting width and height
- Start a new NodeBox script and create an ellipse.
- A circle is an ellipse with an equal width and height so we'll use an expression to link the two together. Click on the arrow button on the left of the "height" parameter to open the parameter menu and select "Toggle Expression".
- In the field that appears, type in the expression
widthand hit Enter. This sets the expression on the height parameter. - Drag the width parameter left and right. Notice that the height follows along to create a perfect square.
- This also works in the viewer. Drag one of the corners of the ellipse and notice that height and width always stay the same.
More complex expressions
Expressions can be more complex than just connecting one parameter to another. By using mathematical expressions you can create some complex effects.
- Change the stroke width parameter to the expression width / 4. This links the thickness of the stroke to the size of the circle.
- Change the alpha-transparency of the fill color to zero by dragging the "Alpha" slider in the color picker all the way to the left.
- Drag the width parameter. Notice that the stroke scales together with the size of the circle.
| To Do: | Type: |
|---|---|
| Addition | alpha + beta
|
| Subtraction | alpha - beta
|
| Multiplication | alpha * 2
|
| Division | alpha / 2
|
| Order of operations | (alpha + 1) / 2
|
Linking two nodes together
- Create a new NodeBox script.
- Create a rect node and ellipse node.
- Create a merge node and connect both the rect and the ellipse. Your network should look like the screenshot.
- The merge node combines the output of multiple nodes into one result. However, you can't see anything since the rectangle and ellipse are on top of eachother.
- Make sure the merge node is the rendered node. Select the ellipse and drag the y parameter to 50, so it peeks out under the rectangle.
- Change the fill color of the ellipse so you know which one is on top. The viewer should look like the screenshot.
- In the merge node, you can change the order of elements by clicking on the name of a node in the parameters view and pressing the up or down arrow.
- We want to move the rectangle and the ellipse together, so that if one moves the other follows. This means linking the X value of the rectangle to that of the ellipse. Either one can have the expression; we'll go for the ellipse.
- Toggle the expression on the x parameter of ellipse1, write
rect1.xand press Enter. The two X values are now linked. - Select the rect1 node (make sure merge1 is rendered) and drag the X value. The ellipse will follow along.
To refer to another node in the expression, use the node name, then a dot, then the parameter name, i.e. rect1.x.
To review
- Use "Toggle Expression" in the parameter menu to turn expressions on or off.
- Expressions are like mathematical constructs.
- The name of the parameter can be found out by hovering your mouse over the parameter label.
- To refer to a parameter on another node use the format
nodename.parametername, i.e.rect1.strokeWidth. - More information can be found in the Expression Reference.
The following tutorial will talk about using expressions to make each copy different.
Next Tutorial: Copy Stamping
Back to the Getting Started page.




