norm()

Normalizes a number from another range into a value between 0 and 1.

Examples

1
2
3
4
def setup():
    value = 20
    n = py5.norm(value, 0, 50)
    py5.println(n)  # Prints "0.4"
1
2
3
4
def setup():
    value = -10
    n = py5.norm(value, 0, 100)
    py5.println(n)  # Prints "-0.1"

Description

Normalizes a number from another range into a value between 0 and 1. Identical to remap(value, low, high, 0, 1).

Numbers outside of the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful. (See the second example.) If that isn’t what you want, try pairing this function with constrain().

Syntax

norm(value: float, start: float, stop: float) -> float

Parameters

  • start: float - lower bound of the value’s current range

  • stop: float - upper bound of the value’s current range

  • value: float - the incoming value to be converted

Updated on September 11, 2021 16:51:34pm UTC