Math Expressions are a powerful tool to create more complex logic in Origami prototypes. Instead of adding patches for each arithmetic operation and connecting them together, you can insert a single Math Expression patch, type the expression you want to compute, and connect its inputs and outputs. Here’s a simple example:
(x + y) / 2
- x 1
- y 5
When you insert a Math Expression patch from the patch picker, it initially has no inputs or outputs. Once you type an expression in the window that appears, the patch updates to include the inputs and outputs from the expression that was entered.
To edit the expression used in a Math Expression patch, right-click the patch and select “Patch Info” from the menu (or press ⌘I). Once you’re done editing, press enter to save the update. Note that changing the title of the patch does not affect the expression.
Example Math Expressions
Compute the distance between two points using the following expression patch. Notice how we included “distance = “ at the beginning of the expression to name the output of the patch.
distance = Math.sqrt((x2-x1) ** 2 + (y2-y1) ** 2)
Create a patch with multiple outputs by writing multiple expressions separated by semicolons:
quotient = a/b; remainder = a % b