Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p5-js map() function in python

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

like image 495
Tissuebox Avatar asked Dec 01 '22 15:12

Tissuebox


1 Answers

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;
};
like image 50
Kevin Workman Avatar answered Dec 04 '22 10:12

Kevin Workman