var aPolygon=Array("Triangle","Square","Pentagon","Hexagon","Heptagon","Octagon","Nonagon","Decagong","Hendecagon","Dodecagon","Triskaidecagon","Tetrakaidecagon","Pentakaidecagon","Hexakaidecagon","Heptakaidecagon","Octakaidecagon","Enneakaidecagon","Icosagon","Icosikaihenagon","Icosikaidigon","Icosikaitrigon","Icosikaitetragon","Icosikaipentagon","Icosikaihexagon","Icosikaiheptagon","Icosikaioctagon","Icosikaienneagon","Triacontagon");
function Window_onload(){Calculate();SetNumeric();if(document.getElementById("sldr").type=="range")document.getElementById("divSldr").style.display="block"}function sldr_onchange(a){document.getElementById("ddSides").selectedIndex=parseInt(a.value)-3;Calculate()}
function Calculate(){var a=parseFloat(document.getElementById("txtRadius").value);if(isNaN(a))alert("Please enter Radius");else{var c=Math.PI*Math.pow(a,2)/1E6,h=document.getElementById("ddSides").value,i=360/h,d=i/(180/Math.PI),b=a*Math.cos(d/2);d=a*Math.sin(d/2)*2;var e=Math.PI*a*2,f=e/h,k=d/2*b,g=k*h;k/=1E6;g/=1E6;document.getElementById("spnCentersBetween").innerHTML=Math.round(d);document.getElementById("spnCentersCircle").innerHTML=Math.round(f);document.getElementById("spnCircleArea").innerHTML=
RoundTo(c,2);document.getElementById("spnCirc").innerHTML=Math.round(e);document.getElementById("spnSliceHeight").innerHTML=Math.round(b);document.getElementById("spnSliceArea").innerHTML=RoundTo(k,3);document.getElementById("spnPolyArea").innerHTML=RoundTo(g,2);var j=aPolygon[h-3];document.getElementById("spnPolyType").innerHTML=j;document.getElementById("spnPoly").innerHTML="Area of "+j;var l=(180-i)/2;a="The "+j+" has "+h+" sides of "+Math.round(d)+" mm, a radius of "+a+" mm, an area of "+RoundTo(g,
2)+" m&sup2;, comprising of "+h+" triangular sections, each with an area of "+RoundTo(k,3)+" m&sup2;, central height of "+Math.round(b)+" mm, inner angle of "+RoundTo(i,1)+"&deg;, and 2 outer angles of "+RoundTo(l,1)+"&deg;.<br /><br />Centers around outer circle circumference = "+Math.round(f)+" mm.<br /><br />The outer circle has a circumference of "+Math.round(e)+" mm, and an area of "+RoundTo(c,2)+" m&sup2;";document.getElementById("spnExplain").innerHTML=a;b=document.getElementById("cnvsPolygon");
if(b.getContext){i=Math.PI/180;a=b.getContext("2d");a.clearRect(0,0,b.width,b.height);c=b.width/2;f=b.width/2;k=-90*i;d=360/h*i;b=k;e=f*Math.cos(b)+c;g=f*Math.sin(b)+c;a.strokeStyle="#000";a.beginPath();a.moveTo(e,g);for(j=0;j<h;j++){b+=d;e=f*Math.cos(b)+c;g=f*Math.sin(b)+c;a.lineTo(e,g)}if(document.getElementById("cbUseColor").checked){a.save();a.fillStyle="#87ceeb";a.shadowOffsetY=10;a.shadowBlur=10;a.shadowColor="#c0c0c0";a.fill();a.restore()}if(document.getElementById("cbDrawSpokes").checked){b=
k;for(j=0;j<h;j++){a.moveTo(c,c);e=f*Math.cos(b)+c;g=f*Math.sin(b)+c;a.lineTo(e,g);b+=d}}a.stroke();if(document.getElementById("cbDrawCircle").checked){a.beginPath();a.strokeStyle="#080";a.arc(c,c,f-1,0,360*i,true);a.stroke()}a.beginPath();a.strokeStyle="#ff0";i=f*Math.cos(d*0.5);a.moveTo(c,c);e=i*Math.cos(b+d*0.5)+c;g=i*Math.sin(b+d*0.5)+c;a.lineTo(e,g);a.stroke()}document.getElementById("sldr").value=h}}var animTimer;function AnimStart(a){animTimer=setInterval("Anim("+a+")",200)}
function AnimStop(){clearInterval(animTimer)}function Anim(a){a=document.getElementById("ddSides").selectedIndex+a;if(a>-1&&a<28){document.getElementById("ddSides").selectedIndex=a;Calculate()}else AnimStop()};