numberLoop

Um método que eu uso bastante quando preciso de um loop em determinado comprimento de elementos

trace(numberLoop(103754, 3));
//2
 
trace(numberLoop(686.9384, 17.53));
//3.268399999999957
 
trace(numberLoop(Math.PI*13/6, Math.PI*2));
//0.5235987755982991 rad - radToDegree == 0.5235987755982991*180/Math.PI -> 30.000000000000014º
 
trace(numberLoop(-2187.4, 2));
//0.599999999999909
 
function numberLoop(n:Number, t:Number):Number {
	if(t<=0){
		throw new Error("Total must be greater thant 0");
	}
 
	return (n%t+t)%t;
}
This entry was posted in as3 and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">