var w,h,ratio,i,s,el,g,div,dragQ,game,my={};function fractionaddMain(rel){my.version='0.61';my.rel=typeof rel!=='undefined'?rel:'../';w=440;h=480;my.sectors=[true];my.denom=3;var s='';s+='
';my.typs=['pizza','circle','square'];my.typ=my.typs[0];s+='
';s+=getRadioHTML('','typ',my.typs,'typChg');s+='
';var sliceClr='hsl(240,100%,90%)' my.fracs=[];my.pizzas=[];my.steps=[{title:'Input',fracStrs:[' ','+'],imgStrs:['','+'],inpQ:true,clr:sliceClr},{title:'Each fraction × other denominator',fracStrs:['=','+'],imgStrs:['','+'],inpQ:false,clr:sliceClr},{title:'Do the multiplies',fracStrs:['=','+'],imgStrs:['','+'],inpQ:false,clr:sliceClr},{title:'Add',fracStrs:['=','='],imgStrs:['',''],inpQ:false,clr:sliceClr},{title:'Simplify',fracStrs:['=',''],imgStrs:['',''],inpQ:false,clr:sliceClr}];for(var i=0;i';s+=''+step.title+'';s+='
';s+='
';for(var n=0;n<2;n++){var id='frac'+i+String.fromCharCode(97+n);s+=strHTML(step.fracStrs[n]);s+='
';s+='';var frac=new Frac(id,2,3,step.inpQ);my.fracs.push(frac);s+='
';} s+='
';s+='
';for(var n=0;n<2;n++){var id='pizza'+i+String.fromCharCode(97+n);s+=strHTML(step.imgStrs[n]);var pizza=new FracImage(id,90);my.pizzas.push(pizza);s+=pizza.html();} s+='
';s+='
';} s+='
© 2018 MathsIsFun.com v'+my.version+'
';s+='
';s+='';document.write(s);for(var i=0;i0){s+='
';s+=str;s+='
';} return s;} function divShow(id,showQ){if(showQ){document.getElementById(id).style.display='inline-block';}else{document.getElementById(id).style.display='none';}} function inputget(id){var v=document.getElementById(id).value;newv=v.replace(/\D/g,'');if(newv!=v){v=newv;document.getElementById(id).value=v;} return v<<0;} function update(){console.log("update",my);var anum=inputget('frac0anum');var aden=inputget('frac0aden');var bnum=inputget('frac0bnum');var bden=inputget('frac0bden');my.pizzas[0].drawMe(anum,aden);my.pizzas[1].drawMe(bnum,bden);if(aden==bden){divShow('step1',false) divShow('step2',false) var cnum=anum*1;var cden=aden;var dnum=bnum*1;var dden=bden;}else{divShow('step1',true) divShow('step2',true) my.fracs[2].setMe(anum+'×'+bden,aden+'×'+bden) my.fracs[3].setMe(bnum+'×'+aden,bden+'×'+aden) var cnum=anum*bden;var cden=aden*bden;var dnum=bnum*aden;var dden=bden*aden;my.fracs[4].setMe(cnum,cden) my.fracs[5].setMe(dnum,dden) my.pizzas[4].drawMe(cnum,cden);my.pizzas[5].drawMe(dnum,dden);} my.fracs[6].setMe(cnum+' + '+dnum,dden) my.fracs[7].setMe(cnum+dnum,dden) var fnum=cnum+dnum var fden=dden if(fnum<=fden){my.pizzas[6].drawMe(fnum,fden);divShow(my.pizzas[7].id,false)}else{my.pizzas[6].drawMe(fden,fden);my.pizzas[7].drawMe(fnum-fden,fden);divShow(my.pizzas[7].id,true)} var gcd=EuclidGCD(fnum,fden) console.log('gcd',gcd);gcd=Math.abs(gcd);if(fnum==0||gcd==1){divShow('step4',false)}else{divShow('step4',true) fnum/=gcd;fden/=gcd;my.fracs[8].setMe(fnum,fden) var decimal=fnum/fden;if(decimal==(decimal<<0)){divShow('frac4b',true) document.getElementById('frac4b').innerHTML='   = '+decimal+'';}else{divShow('frac4b',false)} if(fnum<=fden){my.pizzas[8].drawMe(fnum,fden);divShow(my.pizzas[9].id,false)}else{my.pizzas[8].drawMe(fden,fden);my.pizzas[9].drawMe(fnum-fden,fden);divShow(my.pizzas[9].id,true)}} var visQ=true;if(anum>aden)visQ=false;if(bnum>bden)visQ=false;for(var i=0;i';s+='';} s+='';return s;} function getPlayHTML(w){var s='';s+='';s+='';return s;} function togglePlay(){var btn='playBtn';if(my.playQ){my.playQ=false;document.getElementById(btn).classList.add("play");document.getElementById(btn).classList.remove("pause");}else{my.playQ=true;document.getElementById(btn).classList.add("pause");document.getElementById(btn).classList.remove("play");anim();}} CanvasRenderingContext2D.prototype.drawChosenSectors=function(wd,numer,denom,onClr,offClr,lnClr){g=this;var pos={x:wd/2+1,y:wd/2+1,rad:wd/2} var n=0;if(denom>100){var f=100/denom;numer*=f;denom*=f;} var dAngle=2*Math.PI/denom;var angleNum=0;for(var k=0;k100){var f=100/denom;numer*=f;denom*=f;} var ht=wd;var lt=1;var tp=1;var dWd=wd/denom;var currWd=0;for(var k=0;k';if(this.inputQ){s+='';}else{s+=''+part.val+'';} s+=''} s+='' return s;} Frac.prototype.setMe=function(num,den){document.getElementById(this.id+'num').innerHTML=num;document.getElementById(this.id+'den').innerHTML=den;} function FracImage(id,wd){this.id=id;this.wd=wd;this.ht=wd;this.id=id;this.canid='can'+id;this.imgid='img'+id;} FracImage.prototype.html=function(){s='';s+='
';s+='';s+='';s+='
';return s;} FracImage.prototype.setup=function(){this.el=document.getElementById(this.canid);this.ratio=2;this.el.width=this.wd*this.ratio;this.el.height=this.ht*this.ratio;this.el.style.width=this.wd+"px";this.el.style.height=this.ht+"px";this.g=this.el.getContext("2d");this.g.setTransform(this.ratio,0,0,this.ratio,0,0);} FracImage.prototype.vis=function(visQ){} FracImage.prototype.drawMe=function(numer,denom){numer=numer<<0;denom=denom<<0;var g=this.g;g.clearRect(0,0,g.canvas.width,g.canvas.height);document.getElementById(this.imgid).style.visibility='hidden';if(numer>denom){return;} var posQ=(numer>0);switch(my.typ){case 'pizza':document.getElementById(this.imgid).style.visibility='visible';if(posQ){g.drawChosenSectors(this.wd-2,numer,denom,"rgba(255, 255, 255, 0.0)","rgba(255, 255, 255, 0.8)",'white');}else{g.drawChosenSectors(this.wd-2,-numer,denom,"rgba(255, 0, 0, 0.5)","hsla(0, 100%, 90%, 1)",'white');} break;case 'circle':if(posQ){g.drawChosenSectors(this.wd-2,numer,denom,"#8888ff","white",'#bbb');}else{g.drawChosenSectors(this.wd-2,-numer,denom,"red","white",'#bbb');} break;case 'square':if(posQ){g.drawChosenRectSlices(this.wd-2,numer,denom,"orange","white",'grey');}else{g.drawChosenRectSlices(this.wd-2,-numer,denom,"red","white",'grey');} break;default:}}