/ Published in: ActionScript 3
Credit goes to Bruno Imbrizi.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static function map(num:Number, min1:Number, max1:Number, min2:Number, max2:Number, round:Boolean = false, constrainMin:Boolean = true, constrainMax:Boolean = true):Number { if (constrainMin && num < min1) return min2; if (constrainMax && num > max1) return max2; var num1:Number = (num - min1) / (max1 - min1); var num2:Number = (num1 * (max2 - min2)) + min2; if (round) return Math.round(num2); return num2; }
URL: http://brunoimbrizi.com/unbox/2011/03/mathutils-map/