Math

This page documents the development version of Graphite at dev.graphite.art, which may differ from the current release.

Nodes in this category evaluate math expressions, convert between numbers and text, and generate random numbers.

Nodes

NodeDetailsPossible Types
Format Number

Formats a number as a string with control over decimal places, decimal separator, and thousands grouping.

Number → String
Number[] → String[]
Math Aggregate

Reduces all the items to a single value by folding an operator like + or * across them, or by passing them all to a function like max or mean.

The result is read as the chosen output type: an Integer rounds to the nearest whole number, a Bool reads exactly 0 or 1 as false or true, a Vec2 takes the X and Y of a vector like 3i + 4j, and a Transform takes a matrix like rotation(pi/4) + 5i. Boolean items read as 0 or 1 and Vec2 items as such vectors. Across Transforms, * and / compose in order, mean averages, and count counts.

Number[] → Number
Number[] → Integer
Number[] → Bool
Number[] → Vec2
Number[] → Transform
Integer[] → Number
Integer[] → Integer
Integer[] → Bool
Integer[] → Vec2
Integer[] → Transform
Bool[] → Number
Bool[] → Integer
Bool[] → Bool
Bool[] → Vec2
Bool[] → Transform
Vec2[] → Number
Vec2[] → Integer
Vec2[] → Bool
Vec2[] → Vec2
Vec2[] → Transform
Transform[] → Number
Transform[] → Integer
Transform[] → Bool
Transform[] → Vec2
Transform[] → Transform
Math Formula

Evaluates one math expression over all the items, taking them in order as its arguments a, b, c, …, or A, B, C, … for Transforms.

The result is read as the chosen output type: an Integer rounds to the nearest whole number, a Bool reads exactly 0 or 1 as false or true, a Vec2 takes the X and Y of a vector like 3i + 4j, and a Transform takes a matrix like rotation(pi/4) + 5i. Boolean items read as 0 or 1 and Vec2 items as such vectors.

Number[] → Number
Number[] → Integer
Number[] → Bool
Number[] → Vec2
Number[] → Transform
Integer[] → Number
Integer[] → Integer
Integer[] → Bool
Integer[] → Vec2
Integer[] → Transform
Bool[] → Number
Bool[] → Integer
Bool[] → Bool
Bool[] → Vec2
Bool[] → Transform
Vec2[] → Number
Vec2[] → Integer
Vec2[] → Bool
Vec2[] → Vec2
Vec2[] → Transform
Transform[] → Number
Transform[] → Integer
Transform[] → Bool
Transform[] → Vec2
Transform[] → Transform
Math Function

Maps a value through a math expression written as a function of x, which stands for the value, or of X when it's a Transform. Each item of a list is mapped on its own.

The result is read as the chosen output type: an Integer rounds to the nearest whole number, a Bool reads exactly 0 or 1 as false or true, a Vec2 takes the X and Y of a vector like 3i + 4j, and a Transform takes a matrix like rotation(pi/4) + 5i. A boolean input reads as 0 or 1 and a Vec2 input as such a vector.

Number → Number
Number[] → Number[]
Number → Integer
Number[] → Integer[]
Number → Bool
Number[] → Bool[]
Number → Vec2
Number[] → Vec2[]
Number → Transform
Number[] → Transform[]
Integer → Number
Integer[] → Number[]
Integer → Integer
Integer[] → Integer[]
Integer → Bool
Integer[] → Bool[]
Integer → Vec2
Integer[] → Vec2[]
Integer → Transform
Integer[] → Transform[]
Bool → Number
Bool[] → Number[]
Bool → Integer
Bool[] → Integer[]
Bool → Bool
Bool[] → Bool[]
Bool → Vec2
Bool[] → Vec2[]
Bool → Transform
Bool[] → Transform[]
Vec2 → Number
Vec2[] → Number[]
Vec2 → Integer
Vec2[] → Integer[]
Vec2 → Bool
Vec2[] → Bool[]
Vec2 → Vec2
Vec2[] → Vec2[]
Vec2 → Transform
Vec2[] → Transform[]
Transform → Number
Transform[] → Number[]
Transform → Integer
Transform[] → Integer[]
Transform → Bool
Transform[] → Bool[]
Transform → Vec2
Transform[] → Vec2[]
Transform → Transform
Transform[] → Transform[]
Math Running

Scans along the items, giving each one the result of folding an operator like + over it and every item before it, such as a running total, or of a function like max, such as the highest value so far.

The result is read as the chosen output type: an Integer rounds to the nearest whole number, a Bool reads exactly 0 or 1 as false or true, a Vec2 takes the X and Y of a vector like 3i + 4j, and a Transform takes a matrix like rotation(pi/4) + 5i. Boolean items read as 0 or 1 and Vec2 items as such vectors. Across Transforms, * composes in order, which turns a list of steps into where each step ends up.

Number[] → Number[]
Number[] → Integer[]
Number[] → Bool[]
Number[] → Vec2[]
Number[] → Transform[]
Integer[] → Number[]
Integer[] → Integer[]
Integer[] → Bool[]
Integer[] → Vec2[]
Integer[] → Transform[]
Bool[] → Number[]
Bool[] → Integer[]
Bool[] → Bool[]
Bool[] → Vec2[]
Bool[] → Transform[]
Vec2[] → Number[]
Vec2[] → Integer[]
Vec2[] → Bool[]
Vec2[] → Vec2[]
Vec2[] → Transform[]
Transform[] → Number[]
Transform[] → Integer[]
Transform[] → Bool[]
Transform[] → Vec2[]
Transform[] → Transform[]
Random

The random function (rand) converts a seed into a random number within the specified range, inclusive of the minimum and exclusive of the maximum. The minimum and maximum values are automatically swapped if they are reversed.

→ Number
→ Number[]
String to Number

Parses a string into a number. Falls back to the chosen value if the string is not a valid number.

String → Number
String[] → Number[]