más formulas útiles.
Posted by Andrés Argüello Pittdic 12
Siguiendo con formulas útiles de mi post anterior y estudiando un poco algoritmos Euclidianos, cree un par de funciones para saber cual es la relación de aspecto de una imagen.
function getMCD(w:int, h:int):int{ return ((h != 0) ? arguments.callee(h, w % h): w); } function getAspectRatio(w:uint, h:uint):String{ var mcd:Number = getMCD(w, h); return [(w / mcd), (h / mcd)].join(":"); }
y estos son algunos testeos:
trace (getAspectRatio(320, 240)); // 4:3 trace (getAspectRatio(540, 480)); // 9:8 trace (getAspectRatio(550, 400)); // 11:8

No hay comentarios