cycle(var x,var a,var b);

returns x 'wrapped around' the range a..b.

Parameters:

x - value to be calculated
a
- lower limit
b
- upper limit (not including)

Returns:

x+b-a while x is less than a
x-b+a while x is greater or equal b
x if x is between a and b

Speed:

Fast

Example:

x = cycle(3.5,0,1); // sets x at 0.5

See also:

clamp