var my={} function balancedragMain(){var version='0.83';var w=490;var h=280;my.imgHome=(document.domain=='localhost')?'/mathsisfun/algebra/images/':'/algebra/images/' my.shapes=[];my.wts=[];my.boxWd=20 my.bdName='board0' my.shapeClr='gold' my.zIndex=200 my.transition='0.3s ease-in-out' my.drag={onQ:false} my.bowls=[{id:'bowlLt',zone:{lt:50,mid:116,rt:172,tp:50,bt:240}},{id:'bowlRt',zone:{lt:320,mid:386,rt:450,tp:50,bt:240}}] var s="";s+='' s+='
';s+='
';s+='
';var tp=10;s+='
';s+='
';s+='
';s+='
';s+='
';s+='
';s+='
© 2020 MathsIsFun.com v'+version+'
';s+='
';document.write(s);window.addEventListener('mousemove',function(ev){mouseMove(ev)}) window.addEventListener('touchmove',function(ev){console.log('touchmove') var touch=ev.targetTouches[0];ev.clientX=touch.clientX;ev.clientY=touch.clientY;ev.touchQ=true;mouseMove(ev)}) wtsSetup();balTilt(0)} function mouseMove(ev){if(!my.drag.onQ)return var div=my.drag.div var lt=parseFloat(div.style.left)+ev.clientX-my.drag.x div.style.left=lt+'px' my.drag.x=ev.clientX var tp=parseFloat(div.style.top)+ev.clientY-my.drag.y div.style.top=tp+'px' my.drag.y=ev.clientY} function wtsSetup(){var lens=[1,1,2,2,3,3,4,5];var x=10 var y=10 for(var i=0;i=0;i--){var wt=my.wts[i] if(wt.bowlN==bowlN){wt.div.style.transition=my.transition;wt.setxy(bowl.zone.mid-wt.sz*my.boxWd/2,yPos) wt.draw() bowl.wtSum+=wt.sz yPos-=my.boxWd}}} console.log('bowls',my.bowls)} function balWtTilt(){if(my.bowls[0].wtSummy.bowls[1].wtSum)balTilt(-8) if(my.bowls[0].wtSum==my.bowls[1].wtSum)balTilt(0)} class Wt{constructor(name,sz,clr){this.name=name;this.sz=sz;this.clr=clr;this.hitN=0;this.showQ=true;this.canPad=4 this.xn=sz;this.yn=1;this.bowlN=-1;this.pad=0;this.div=document.createElement("div");this.div.style.transition="";this.div.style.pointerEvents="auto" this.div.style.zIndex=my.zIndex++;this.can=document.createElement('canvas');this.g=this.can.getContext("2d");this.div.appendChild(this.can);document.getElementById(my.bdName).appendChild(this.div);this.setSize();var div=this.div;var me=this;me.drag={onQ:false,x:0,y:0};div.addEventListener('touchstart',function(ev){if(!me.showQ)return;console.log('touchstart');me.drag.onQ=true;me.drag.x=ev.clientX;me.drag.y=ev.clientY;me.div.style.zIndex=my.zIndex++;me.div.style.transition="";me.goneOutQ=true;var touch=ev.targetTouches[0];ev.clientX=touch.clientX;ev.clientY=touch.clientY;ev.touchQ=true;ev.preventDefault();});div.addEventListener('touchend',function(){me.dropMe(me);});div.addEventListener('mouseover',function(){document.body.style.cursor="pointer";});div.addEventListener('mousedown',function(ev){me.drag.onQ=true;me.drag.x=ev.clientX;me.drag.y=ev.clientY;me.drag.div=me.div me.div.style.zIndex=my.zIndex++;me.div.style.transition="";ev.stopPropagation() my.drag=me.drag me.goneOutQ=true;});div.addEventListener('mouseleave',function(ev){me.moveMe(me,ev);});div.addEventListener('mouseup',function(){me.dropMe(me);});} dropMe(me){me.drag.onQ=false;my.borderLt=0;my.borderTp=0;var lt=parseFloat(me.div.style.left);me.div.style.left=lt+'px';var tp=parseFloat(me.div.style.top);me.div.style.top=tp+'px';console.log('dropMe',lt,tp,me.div.style.top,my.boxWd,my.boxWd*this.sz);me.bowlN=-1;for(var i=0;i=this.sz){this.sunkQ=true;soundPlay('sndSunk');this.show(true);console.log('ship just sunk');for(var i=0;ir.rt)return false if(yr.bt)return false return true}