Is there a function like the map() of p5-js in python? the map() in python isn't the same at all, as I understood it, in python it apply same function to all the iterable in a sequence but I need something that does what the map() function in p5-js does, thanks for helping!
EDIT: the map() in p5-js takes 5 arguments exemple:
map(100, 0, 200, 0, 50)
the first argument is the value you want mapped
the second argument is the minimum of that value
the third argument is the maximum
the fourth argument is the minimum of the mapping you wanna do
the fifth argument is the maximum of the mapping you wanna do
so in my exemple, it would return 25, as 100 is halfway through its minimum(0) and maximum(200). 25 is halfway throught 0 and 50. if you did:
map(50, 50, 100, 100, 200)
it would return 100. 50 (the first argument) is the first value between 50 and 100. and 100 is the first value between 100 and 200
P5.js is open source, and you can view the source for the map()
function here.
p5.prototype.map = function(n, start1, stop1, start2, stop2) {
return ((n-start1)/(stop1-start1))*(stop2-start2)+start2;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With