let my={} function findingbugsMain(mode='rat'){let version='0.62';my.mode=mode my.countMax=10 my.countN=3 my.countFrac=my.countN/my.countMax my.findRad=50 my.alphaLo=0.16 my.bugs=[{img:'butterfly.svg'},{img:'dragonfly.svg'}] my.bug=my.bugs[0] let s='' my.sndHome=(document.domain=='localhost')?'/mathsisfun/images/sounds/':'/images/sounds/' s+='';s+='';s+='' my.snds=[];my.soundQ=true s+='
';my.imgHome=(document.domain=='localhost')?'/mathsisfun/games/images/bugs/':'/games/images/bugs/' s+='';for(var i=0;i';} s+='' s+='' s+='
';s+=soundBtnHTML() s+='
';s+='
Well Done!
';s+='
© 2020 MathsIsFun.com v'+version+'
';s+='
';document.write(s);let styles=getComputedStyle(document.getElementById('outer')) my.wd=parseFloat(styles.width) my.ht=my.wd*900/1260 my.cans=[] canvasInit('canScore',my.wd,my.wd*0.1,2) canvasInit('canHover',my.wd,my.ht,1) console.log('my',my) window.addEventListener("mousemove",onMouseMove,false);window.addEventListener("mousedown",onMouseDown,false);go() scoreDraw() success()} function canvasInit(id,wd,ht,ratio){let el=document.getElementById(id);el.width=wd*ratio;el.style.width=wd+"px";el.height=ht*ratio;el.style.height=ht+"px";let g=el.getContext("2d");g.setTransform(ratio,0,0,ratio,0,0);my.cans[id]={el:el,g:g,ratio:ratio}} function onMouseMove(evt){let div=document.getElementById('outer') let bRect=div.getBoundingClientRect();let mouseX=(evt.clientX-bRect.left) let mouseY=(evt.clientY-bRect.top) let g=my.cans.canHover.g g.clearRect(0,0,g.canvas.width,g.canvas.height) g.fillStyle='rgba(250,250,200,0.3)' g.beginPath() g.arc(mouseX,mouseY,my.findRad,0,2*Math.PI) g.fill();for(let i=0;i=0){let shape=my.shapes[closeN] shape.foundQ=true let div=document.getElementById('bf'+closeN);div.style.opacity=1 my.score+=1 soundPlay('sndDrop') scoreDraw()}} function scoreDraw(){let g=my.cans.canScore.g g.clearRect(0,0,g.canvas.width,g.canvas.height) let ht=my.wd*0.05 let lt=my.wd*0.14 g.strokeStyle='rgba(0,0,200,0.2)' g.fillStyle='rgba(200,200,250,0.5)' g.beginPath() g.rect(lt,10,my.wd*0.6,ht) g.stroke() g.fill();g.fillStyle='rgba(0,0,200,0.6)' g.beginPath() let wd=my.score/my.countN*my.wd*0.6 g.rect(lt,10,wd,ht) g.fill();g.fillStyle='white' g.font=parseInt(ht)+'px Arial' g.fillText(my.score,lt+wd-30,ht*1.1) if(my.score==my.countN){success(true)}} function success(yesQ){let div=document.getElementById('success') div.style.font=(my.wd*0.1)+'px Arial' if(yesQ){div.style.left=(my.wd*0.2)+'px' div.style.top=(my.wd*0.065)+'px' div.style.opacity=1 soundPlay('sndYes') my.alphaLo-=0.05 my.alphaLo=Math.max(my.alphaLo,0) my.countFrac+=0.0501 my.countFrac=Math.min(my.countFrac,1) my.countN=parseInt(my.countFrac*my.countMax) setTimeout(go,1500)}else{div.style.left=(-my.wd)+'px' div.style.top=(my.wd*0.1)+'px' div.style.opacity=0}} function go(){my.shapes=[];my.score=0 scoreDraw() success(false) my.findRad=my.wd*0.08 let lt=50 let tp=50 let trys=0 do{let wd=(0.8+Math.random()*0.2)*my.wd*0.1 let ht=wd lt=Math.random()*(my.wd-wd-20) tp=my.ht*0.15+Math.random()*my.ht*0.7 let closeQ=false for(i=0;i0)document.getElementById(id).play()}else{my.snds.push(id) soundPlayQueue(id)}} function soundPlayQueue(id){let div=document.getElementById(my.snds[0]) div.play() div.onended=function(){my.snds.shift();if(my.snds.length>0)soundPlayQueue(my.snds[0]);};} function soundToggle(){let btn='sound' if(my.soundQ){my.soundQ=false document.getElementById(btn).classList.add("mute")}else{my.soundQ=true document.getElementById(btn).classList.remove("mute")}}