Concepts

Math Expressions

Math Expressions

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

Math Expression

  • x 1
  • y 5
  • 3

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.

Math Expression Editor

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.

Expressions can include any mathematical operations (+, -, *, /, %, **) or functions from the JavaScript Math library. Any expression that is valid in JavaScript can be used, but the inputs and outputs can only be numbers. If you type an invalid expression into the editor, it will not be saved and will be highlighted in red.

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)

distance = Math.sqrt((x2-x1) ** 2 + (y2-y1) ** 2)

Math Expression

  • y2
  • y1
  • y2
  • x1
  • distance

Create a patch with multiple outputs by writing multiple expressions separated by semicolons:

quotient = a/b; remainder = a % b

quotient = a/b; remainder = a % b

Math Expression

  • a
  • b
  • quotient
  • remainder