Calculate Aspect Ratio
Calculate Aspect Ratio
by Nirvanachain
JavaScript
function gcd (a, b) {
return (b == 0) ? a : gcd (b, a%b);
}
var w = screen.width;
var h = screen.height;
var r = gcd (w, h);
document.write ("<pre>");
document.write ("Dimensions = ", w, " x ", h, "<br>");
document.write ("Gcd = ", r, "<br>");
document.write ("Aspect = ", w/r, ":", h/r);
document.write ("<br />");
document.write ("<br />");
document.write ("Find the greatest common divisor (GCD) and divide both values by that.<br /> The GCD is the highest number that evenly divides both numbers.<br /> So the GCD for 6 and 10 is 2, the GCD for 44 and 99 is 11.");
document.write ("</pre>");