【Tips】Processingのmap()関数をJavaScriptで
Processingのmap()関数が便利なので、JavaScriptで同じ動作をする関数を作りました。
map(変換したい変数, 数字の最小値, ~最大値, 欲しい最小値, ~最大値);
ex )
map(10, 0, 100, 0, 200);
変換前
10
変換後
20
function map(value, start1, end1, start2, end2) { return start2 + (end2 - start2) * ((value - start1) / (end1 - start1)); }
【参考URL】
map()\ Language (API) \ Processing 2+ https://www.processing.org/reference/map_.html
c/c++でmap() http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1375788868