Extensions to the built-in
Number#constrain(min, max) -> Number
minif number is less than
maxif number is greater than
max. Returns itself otherwise.
Number#nearer(n1, n2) -> Number
n2— whichever is closer to the number, in absolute terms.
Number#tween(target, position) -> Number
Number) – tween target
Number) – position between 0 (start of tween) and (end of tween); can also be < 0 and > 1.
Returns the number that is a given percentage between this number and a target number.
(1).tween(2, 0.5) -> 1.5 (1).tween(2, 0) -> 1 (1).tween(2, 1) -> 2