var w,h,ratio,el,g,my={};function patternmatchMain(mode){var version='0.63';my.type=typeof mode!=='undefined'?mode:'clr';console.log("my.type",my.type);w=500;h=350;my.hards=[{title:'Easy',seqLen:2,patFix:8,patRand:2,secretLen:2,score:10},{title:'Basic',seqLen:3,patFix:10,patRand:3,secretLen:3,score:20},{title:'Hard',seqLen:4,patFix:12,patRand:4,secretLen:4,score:50},{title:'Tough',seqLen:5,patFix:16,patRand:0,secretLen:5,score:100}];my.types=[{id:'num',title:'Numbers'},{id:'clr',title:'Colors'},{id:'shape',title:'Shapes'},{id:'ltr',title:'Letters'}] my.typeN=0 for(var i=0;i';s+='';s+='';s+='';my.snds=[];s+='
';s+='
';s+='';s+='';my.soundQ=true s+=' ' s+=soundBtnHTML() s+='
';s+='
';s+=btnHTML();s+='
';s+='
';s+='';s+='
';s+='
';s+=optPopHTML();s+='
';s+='
';s+='
© 2019 MathsIsFun.com v'+version+'
';s+='
';document.write(s);if(my.type=='shape'){for(var i=0;i=seq.length){counter=0} a++} my.pat=[] a=0 while(a5){this.prevPt={x:this.pt.x,y:this.pt.y} var posX=this.stt.x+this.frame*30;var posY=this.stt.y;var temp=0;if(my.pathType=="sin"){posY=this.stt.y+this.amplitude*Math.sin((this.sttangle+posX*100/this.wavelength)*0.01745);} if(my.pathType=="angle"){var temp=this.stt.y+this.amplitude*Math.sin((this.sttangle+posX*100/this.wavelength)*0.01745);var ang=Math.atan2(temp-this.prevPt.y,posX-this.prevPt.x) var d=my.rad*2+2;posX=this.prevPt.x+Math.cos(ang)*d;posY=this.prevPt.y+Math.sin(ang)*d;} this.pt={x:posX<<0,y:posY<<0} var elemNo=my.pat[this.frame] elemDraw(g,this.pt,'num',elemNo,false) soundPlay('sndPlace') this.pts.push(this.pt) this.frame++;this.wait=0} if(this.frame'+my.nums[i]+'';break;case 'ltr':s+='';break;case 'clr':s+='';break;case 'shape':s+='';break;default:}} s+='';return s;} function keyOver(typ,n){switch(typ){case 'clr':hint(my.clrs[n][0]) break;case 'shape':hint(my.shapes[n]) break;default:}} function keyOut(){hint('')} function typeChg(n){my.type=my.types[n].id;console.log('typeChg',n,my.type);var div=document.getElementById('choices') div.innerHTML=btnHTML();if(my.type=='shape'){for(var i=0;i';s+=radioHTML('Level: ','hard',my.hards,'hardChg',0);s+='';s+='
';s+=radioHTML('Type: ','type',my.types,'typeChg',my.typeN);s+='
';s+='';s+='
';s+='';s+='';s+='
';s+='';return s;} function optPop(){var pop=document.getElementById('optpop');pop.style.transitionDuration="0.3s";pop.style.opacity=1;pop.style.zIndex=12;pop.style.left='20px';} function optYes(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';} function optNo(){var pop=document.getElementById('optpop');pop.style.opacity=0;pop.style.zIndex=1;pop.style.left='-999px';} function soundBtnHTML(){var s='' s+='' s+='
' return s} function soundToggle(){var btn='sound' if(my.soundQ){my.soundQ=false document.getElementById(btn).classList.add("mute")}else{my.soundQ=true document.getElementById(btn).classList.remove("mute")}} function soundPlay(name,simulQ){if(!my.soundQ)return simulQ=typeof simulQ!=='undefined'?simulQ:true if(simulQ){if(name.length>0){var div=document.getElementById(name) if(div.currentTime>0&&div.currentTime0)soundPlayQueue();};} function radioHTML(prompt,id,lbls,func,chkN){var s='';s+='
';s+=prompt;for(var i=0;i';s+='';} s+='
';return s;} function random(){var x=Math.sin(my.seed++)*10000;return x-Math.floor(x);}