Advertisement
framp

ofMap JS implementation

Nov 17th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //http://www.openframeworks.cc/documentation/math/ofMath.html#show_ofMap
  2. function ofMap(value, r1a, r1b, r2a, r2b, clamp){
  3.   if (clamp && value<=r1a)
  4.     return r2a;
  5.   if (clamp && value>=r1b)
  6.     return r2b;
  7.   var r1 = r1b-r1a;
  8.   var r2 = r2b-r2a;
  9.   return r2a+(value-r1a)*r2/(r1b-r1a)
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement