Skip to main content

Overview

This function returns a value constrained between a minimum and maximum. If the value is lower than the minimum, the minimum is returned, and if the input is higher than the maximum, the maximum is returned.

Parameters

clamp(value, min, max)
  • Value: The number to constrain within the specified minimum and maximum range.
    • Pro tip: Use an Expression Editor property, like Pan.translationY, as the value to follow a user’s gesture, then clamp it to keep the result within a defined range.
  • Min: The value at the start of the range. The function cannot return a value lower than this.
  • Max: The value at the end of the range. The function cannot return a value higher than this.

Example

clamp(11, 0, 20)
Returns 11 (the true value).
clamp(-1, 0, 20)
Returns 0 (the min value).
clamp(22, 0, 20)
Returns 20 (the max value).