Command like map() in processing?

Is there a map function like the one in processing? In 1.5?

Thanks :slight_smile:

You can have it now.

I haven’t tested this, but it should work:

function map( value, start1, stop1, start2, stop2 )
    local norm = (value - start1) / (stop1 - start1)
    
    norm = norm * (stop2 - start2) + start2

    return norm
end

```

Thanks simeon.

I’l try it out.

You know, I never noticed this function before, but it looks to be incredibly helpful in mapping screen coordinates. Thanks!

I don’t understand how to use this function.
Can you explain me?

It re-maps a value from one range to another.

Say you have a number from -10 to 10 (called myNumber), and you want it represented as a number from 0 to 1, you can do:

result = map( myNumber, -10, 10, 0, 1 )

So the following values of myNumber would map as follows:

-10 => 0

0 => 0.5

10 => 1

Ok thank you for this explanation. Now I understand why it’s so interesting!